5 Replies Latest reply on Jan 4, 2010 7:57 AM by daniell

    missing JavaScript imports when programmatically including RichFaces components

    daniell
      Hi again!

      I have another question, which is closely related to my previous one (http://community.jboss.org/message/517962).

      As written there, I've created a custom JSF component, which includes a RichFaces Calendar programmatically. I'm testing my new component in a page, where also other RichFaces calendars are displayed and everything is working.

      But when I create a new page with only my new component (or if I delete the other Calendar components from the test page), some JavaScript-Imports are missing and the Calendar PopUp is not working anymore.

      Do I somehow have to define dependencies or (better) can I inherit these dependencies from the RichFaces Calendar?

      Thanks!
        • 1. Re: missing JavaScript imports when programmatically including RichFaces components
          daniell

          I already found a working solution in setting the LoadScriptStrategy and LoadStyleStrategy in the web.xml file to "ALL".

          But why isn't it possible to load the scripts on demand? Are there any drawbacks in changing the strategies (except those mentionend in Chapter 5 of the Dev-Guide)?

          • 2. Re: missing JavaScript imports when programmatically including RichFaces components
            nbelaevski

            Hi,

             

            This should work ok. Please post the code used for calendar inclusion.

            1 of 1 people found this helpful
            • 3. Re: missing JavaScript imports when programmatically including RichFaces components
              daniell

              As suggested by several books and tutorials, I split up the JSF component code into three main classes.

              In the component class (with the prefix UI) which extends UIInput, I create the instance of the RichFaces calendar using "new HtmlCalendar()" and keep it as private property.

              I also set the datePattern and other configuration stuff in this component class.

               

                  private HtmlCalendar rfCalendar;
              
                  public UIVisCalendar() {
                      rfCalendar = new HtmlCalendar();
                      configureRfCalendar();
                  }
              
              
                  private void configureRfCalendar() {
                      rfCalendar.setConverter(getDateConverter());
                      rfCalendar.setDatePattern("dd.MM.yyyy");
                      rfCalendar.setImmediate(true);
                      rfCalendar.setEnableManualInput(true);
                  }
              
                  public HtmlCalendar getRfCalendar()
                  {
                      return rfCalendar;
                  }
              

               

               

              In the renderer class (with the suffix Renderer) which extends AjaxComponentRendererBase, where I've access to my component class, there's some code to do additional (conditional) configuration stuff of the RF calendar. But basically I "draw" the RF calendar by calling the method encodeAll(context) in the Renderer's doEncodeBegin(...) method. The following snippet shows the important lines dealing with the RF calendar.

               

                  public void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent component)
                      throws IOException
                  {
                      UIVisCalendar calendarVis = (UIVisCalendar) component;
                      String clientId = component.getClientId(context);
              
                      writer.startElement("div", null);
                      
                      // the RichFaces component for the date input
                      calendarVis.getRfCalendar().setParent(component);
                      calendarVis.getRfCalendar().setValue(calendarVis.getValue());
                      calendarVis.getRfCalendar().encodeAll(context);
                      writer.endElement("div");
                  }
              
              
              • 4. Re: missing JavaScript imports when programmatically including RichFaces components
                nbelaevski

                You should add created calendar to component tree explicitly:

                component.getChildren().add(calendar);
                

                or

                component.getFacets().put("calendar", calendar);
                
                • 5. Re: missing JavaScript imports when programmatically including RichFaces components
                  daniell
                  Thank you! The things are getting clearer