5 Replies Latest reply on Oct 11, 2011 2:39 AM by ozorin

    Problem adding UICalendar programmatically

    scott.jones618

      Hello, using RichFaces 4.0.0, JSF 2.0, Facelets.

       

      I'm adding form inputs to an HtmlPanelGrid and binding that to an h:panelGrid on my input form.  When I add a UICalendar to the form programmatically it shows up but it is always read only.

       

      UICalendar input = new UICalendar();
      input.setId(eachParam.getName());
      input.setValue(eachParam.getValue());
      input.setRequired(eachParam.isRequired());
      
      htmlPanelGrid.getChildren().add(input);
      

       

      I've even tried setting attributes like this to no avail:

       

      input.getAttributes().put("readonly", false);
      input.getAttributes().put("disabled", false);
      

      When I add a rich:calendar tag in the xhtml file it shows up as editable as I would expect it to.

       

      Another bit of weirdness is this: when I add the rich:calendar mark-up tag to the same form that I add the progammatic UICalendar, it magically makes the programmatic one editable as well.

       

      Any ideas?

        • 1. Re: Problem adding UICalendar programmatically
          scott.jones618

          Anybody?

          • 2. Re: Problem adding UICalendar programmatically
            scott.jones618

            It appears the problem is due to RichFaces automagically importing numerous JavaScript libraries when I use the markup (<rich:calendar/>) but not when I add the calendar programmatically.

             

            <script type="text/javascript" src="/ASR_Web/javax.faces.resource/jsf.js.jsf?ln=javax.faces&amp;stage=Development"><!--

             

            //--></script><script type="text/javascript" src="/ASR_Web/javax.faces.resource/jquery.js.jsf"><!--

             

            //--></script><script type="text/javascript" src="/ASR_Web/javax.faces.resource/jquery.position.js.jsf"><!--

             

            //--></script><script type="text/javascript" src="/ASR_Web/javax.faces.resource/richfaces.js.jsf"><!--

             

            //--></script><script type="text/javascript" src="/ASR_Web/javax.faces.resource/richfaces-base-component.js.jsf"><!--

             

            //--></script><script type="text/javascript" src="/ASR_Web/javax.faces.resource/richfaces-event.js.jsf"><!--

             

            //--></script><script type="text/javascript" src="/ASR_Web/javax.faces.resource/json-dom.js.jsf?ln=org.richfaces"><!--

             

            //--></script><script type="text/javascript" src="/ASR_Web/javax.faces.resource/jquery.effects.core.js.jsf?ln=org.richfaces"><!--

             

            //--></script><script type="text/javascript" src="/ASR_Web/javax.faces.resource/jquery.effects.highlight.js.jsf?ln=org.richfaces"><!--

             

            //--></script><script type="text/javascript" src="/ASR_Web/javax.faces.resource/JQuerySpinBtn.js.jsf?ln=org.richfaces"><!--

             

            //--></script><script type="text/javascript" src="/ASR_Web/javax.faces.resource/calendar-utils.js.jsf?ln=org.richfaces"><!--

             

            //--></script><script type="text/javascript" src="/ASR_Web/javax.faces.resource/calendar.js.jsf?ln=org.richfaces"><!--

             

            //--></script><link rel="stylesheet" media="screen" type="text/css" href="/ASR_Web/rfRes/calendar.ecss.jsf?db=eAFjj-dWAgABdQCU&amp;ln=org.richfaces" />

            • 3. Re: Problem adding UICalendar programmatically
              nbelaevski

              Hi Scott,

               

              You should use application.createComponent(FacesContext, String, String) method to create component programmatically, not a pure 'new' operator - see JSF specification for more info.

              • 4. Re: Problem adding UICalendar programmatically
                scott.jones618

                Is this what you mean?

                 

                FacesContext facesContext = FacesContext.getCurrentInstance();

                Application application = facesContext.getApplication();

                application.createComponent(facesContext, UICalendar.COMPONENT_TYPE, "org.richfaces.renderkit.html.CalenderRenderer");

                • 5. Re: Problem adding UICalendar programmatically
                  ozorin

                  Dear All,

                  is there any other ideas?