1 2 Previous Next 22 Replies Latest reply on Jun 18, 2012 10:26 AM by Michael Vu

    calendar input rerender onchange

    Daniel Soneira Novice

      hi,

      I want to accomplish the following task:

      Whenever ANYTHING is entered into the calendar's input field the value has to be submitted and converted.

      Our (enhanced) DateTimeConverter can understand values like
      "24.12" => 24.12.$currentyear
      "2412" => 24.12.$currentyear
      "01" => 01.$currentmonth.$currentyear

      .. you get the drill ;)

      I was able to do that with the Tomahawk calendar component like this:

      <t:inputCalendar id="${id}"
       value="${value}"
       maxlength="10"
       size="12"
       renderAsPopup="true">
       <f:convertDateTime pattern="dd.MM.yyyy" timeZone="CET"/>
       <a4j:support event="onchange"
       reRender="${id}"
       ajaxSingle="true"/>
      </t:inputCalendar>


      => that submitted the value on change event and invoked our converter (registered as javax.faces.DateTime).


      I now want to replace that with the rich:calendar component, but have not succeeded thus far:
      <rich:calendar popup="true" enableManualInput="true" ajaxSingle="true" datePattern="dd.MM.yyyy" converter="javax.faces.DateTime">
       <iwms:displayName value="${displayName}"/>
       <a4j:support event="onchange" ajaxSingle="true" reRender="${id}"/>
      


      I also tried "ondateselect"... I successfully tried the oninputchange attribute with a alert script - so i guess if i come up with a javascript function, that does the same thing as my converter, that would work...
      But I would definitely prefer the JSF-Converter, since that one is already working ;)

      Long question short - is it possible to reRender the calendar/input component during "onchange" event of the calendar INPUT field?

      Kind regards,
      Daniel

        • 1. Re: calendar input rerender onchange
          Ilya Shaikovsky Master

          use

          oninputchange
          oninputfocus
          oninputblur
          oninputkeyup

          etc.. ;)

          • 2. Re: calendar input rerender onchange
            Daniel Soneira Novice

            I simply forgot to assign an ID to the calender (the one used in reRender attribute) -> therefore it did not work :)

            After I got that working I stumbled across something you might consider a bug:

            If you try to enter some TEXT into the calendar input field (enableManualInput="true") a ParseException is thrown in CalendarRendererBase.

            Since a ConverterException is already thrown before I think the Renderer should not try to convert again (why is it converting in the first place?)

            That results in an ugly Server ERROR 500 page - instead of a simple faces-message (because it occurs in the RENDER phase).

            <rich:calendar id="test" popup="true" enableManualInput="true">
             <f:convertDateTime timeZone="CET" pattern="dd.MM.yyyy"/>
             <a4j:support event="oninputchange" ajaxSingle="true" reRender="test"/>
            </rich:calendar>


            java.text.ParseException: Unparseable date: "asdf"
             at java.text.DateFormat.parse(DateFormat.java:335)
             at javax.faces.convert.DateTimeConverter.getAsObject(DateTimeConverter.java:71)
             at org.richfaces.renderkit.CalendarRendererBase.getSelectedDate(CalendarRendererBase.java:356)
             at org.richfaces.renderkit.html.CalendarRenderer.doEncodeEnd(CalendarRenderer.java:218)
             at org.richfaces.renderkit.html.CalendarRenderer.doEncodeEnd(CalendarRenderer.java:427)
             at org.ajax4jsf.renderkit.RendererBase.encodeEnd(RendererBase.java:135)
             at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:539)
             at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:286)
             at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:143)
             at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:86)
             at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:134)
             at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:86)
             at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:134)
             at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:86)
             at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:134)
             at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:86)
             at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:134)
             at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:86)
             at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:134)
             at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:86)
             at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:134)
             at org.ajax4jsf.renderkit.AjaxContainerRenderer.encodeAjax(AjaxContainerRenderer.java:122)
             at org.ajax4jsf.component.UIAjaxRegion.encodeAjax(UIAjaxRegion.java:239)
             at org.ajax4jsf.context.AjaxContextImpl.renderAjaxRegion(AjaxContextImpl.java:289)
             at org.ajax4jsf.context.AjaxContextImpl$2.invoke(AjaxContextImpl.java:204)
             at org.ajax4jsf.context.JsfOneOneInvoker.invokeOnComponent(JsfOneOneInvoker.java:78)
             at org.ajax4jsf.context.JsfOneOneInvoker.invokeOnComponent(JsfOneOneInvoker.java:83)
             at org.ajax4jsf.context.AjaxContextImpl.invokeOnComponent(AjaxContextImpl.java:160)
             at org.ajax4jsf.context.AjaxContextImpl.renderSubmittedAjaxRegion(AjaxContextImpl.java:218)
             at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:239)
             at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
             at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
             at javax.faces.webapp.FacesServlet.service(FacesServlet.java:140)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
             at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
             at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
             at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
             at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
             at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
             at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
             at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
             at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
             at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
             at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
             at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
             at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
             at java.lang.Thread.run(Thread.java:595)


            • 3. Re: calendar input rerender onchange
              Ilya Shaikovsky Master

              there is such a bug on calendar conversion present.

              • 4. Re: calendar input rerender onchange
                Daniel Soneira Novice

                I found a bug report concerning calendar conversion, but it does not really consider what I think is wrong RF-934

                That bug report describes that the user defined converter is not used at all.
                My complaint is, that a conversion happens in a RENDERER which should not be the case - the renderer should only take the value as is (it was converted before) and not invoke any converter at that phase at all.

                see CalendarRendererBase.getSelectedDate

                Kind regards,
                Daniel

                • 5. Re: calendar input rerender onchange
                  Maksim Kaszynski Apprentice

                  Yep, it turns to be a completely different issue.
                  What is the desired behavior of calendar in case of bad user input?
                  Text field will display last user input. As for calendar grid - which date should it display then? Last date user selected - I suppose.
                  I'll submit it to our jira then.

                  • 7. Re: calendar input rerender onchange
                    Jeff Jo Newbie

                    I was having a similar problem with <rich:calendar>. The fix was to put an <f:convertDateTime/> within the <rich:calendar> tag.

                    Also, the important thing to note here is that the pattern attribute for BOTH <rich:calendar> and <f:convertDateTime> NEED to be the same.

                    Example:

                    <rich:calendar popup="true" showInput="true" enableManualInput="false"
                    value="#{controller.currentDate}"
                    datePattern="MM/dd/yyyy" id="myDate" >
                     <f:convertDateTime pattern="MM/dd/yyyy"
                     timeZone="#{timeZoneHelper.currentTimeZone}" />
                    </rich:calendar>


                    If the datePattern attribute for <rich:calendar/> and the pattern attribute for <f:convertDateTime> are NOT the same, then you will get an unparseable date error.

                    • 8. Re: calendar input rerender onchange
                      Daniel Soneira Novice

                       

                      "maksimkaszynski" wrote:
                      http://jira.jboss.com/jira/browse/RF-997


                      I'm disappointed to wait for a BUG fix until version 1.2 - and seeing other NEW features implemented on the way -_-

                      • 9. Re: calendar input rerender onchange
                        Benedek Fazekas Newbie

                         

                        "jeffzzang" wrote:
                        I was having a similar problem with <rich:calendar>. The fix was to put an <f:convertDateTime/> within the <rich:calendar> tag.


                        Your workaround unfortunately not working for me. I am getting the same exception as quoted here in this thread. My code is:
                        <rich:calendar
                         id="doc_expireDate"
                         datePattern="MM/dd/yyyy"
                         value="#{pax.apisDocument.expireDate}"
                         enableManualInput="true"
                         styleClass="calendar"
                         timeZone="#{apisBean.defaultTimeZone}"
                         converterMessage="#{msgs.RK_ERROR_INVALID_DATE}"
                         >
                         <f:convertDateTime pattern="MM/dd/yyyy" timeZone="#{apisBean.defaultTimeZone}" />
                         </rich:calendar>
                        


                        i am using richfaces version 3.1.2.GA with myfaces 1.1.5 (i guess it does not matter but still). Any idea why? In what environment have you managed to make this workaround work?

                        Or your workaround is not for http://jira.jboss.com/jira/browse/RF-997 (mentioned by daniel.soneira)?

                        • 10. Re: calendar input rerender onchange
                          Daniel Soneira Novice

                          So, when is RF-997 going to be reopened, since it has not been fixed with RF-933?

                          • 12. Re: calendar input rerender onchange
                            Daniel Soneira Novice

                            Thanks, do you think you can fix this in 3.1.3?

                            I want to exchange the Tomahawk calendar with the RichFaces one - this is the only bug that stands in my way of doing so :)

                            • 13. Re: calendar input rerender onchange
                              Alexej Newbie

                              maybe I understand this problem wrong? but on my side all works fine.

                              If I enter "asd" in calendar input and than submits the form I get faces message: " 'asd' could not be understood as a date. Example: 11/22/2007. " that is here wrong?

                              Best regards Alexej.

                              • 14. Re: calendar input rerender onchange
                                Daniel Soneira Novice

                                If you get a faces message everything is fine - i will download the latest build of 3.1.3 and try again.

                                Is it possible that Facelets is the source of the problem? - Evaluating ... I'll give you my results as soon as possible.

                                1 2 Previous Next