4 Replies Latest reply on Jan 8, 2009 11:26 AM by nbelaevski

    Prevent resource loading in a custom tag

      Hi
      I have a custom tag that represents a popup calendar and uses jQuery library. Now its ok but the jQuery is loading twice when there is another richfaces component on the page. So my question is how can I prevent this behavior?

        • 1. Re: Prevent resource loading in a custom tag
          nbelaevski

          Hello,

          This should not happen. Please provide custom tag code.

          • 2. Re: Prevent resource loading in a custom tag

            This is almost the whole part of the tag:

            public class UICalendar extends UIComponentBase {
            
             private static final String RESOURCE_PATH_CAL = "resource:///path/calendar.js";
            
             private static final String RESOURCE_PATH_JQUERY = "resource:///org/richfaces/renderkit/html/scripts/jquery/jquery.js";
            
             @Override
             public void encodeBegin(FacesContext context) throws IOException {
            
             if (!(getParent() instanceof UIInput)) {
             throw new IllegalStateException(
             "The ecs:calendar tag should be nested inside inputText!");
             }
            
             if (!Contexts.getEventContext().isSet(CALENDAR_SCRIPT)) {
             HtmlLoadScript jqueryLoader = new HtmlLoadScript();
             jqueryLoader.setSrc(RESOURCE_PATH_JQUERY);
             getChildren().add(jqueryLoader);
            
             HtmlLoadScript script = new HtmlLoadScript();
             script.setSrc(RESOURCE_PATH_CAL);
             getChildren().add(script);
            
             Contexts.getEventContext().set(CALENDAR_SCRIPT, "loaded");
             }
            
             String query = "showCalendar(this)";
             getParent().getAttributes().put(EVENT_TYPE, query);
            
             if (getParent().getAttributes().get(STYLE_CLASS) == null) {
             getParent().getAttributes().put(STYLE_CLASS,
             INTERACTIVE_FIELD_CLASS);
             } else {
             getParent().getAttributes().put(
             STYLE_CLASS,
             ((String) getParent().getAttributes().get(STYLE_CLASS))
             .concat(" " + INTERACTIVE_FIELD_CLASS));
             }
             }
            
             @Override
             public String getFamily() {
             return COMPONENT_FAMILY;
             }
            }




            • 3. Re: Prevent resource loading in a custom tag
              amitev

              Is it needed to extend AjaxRenderer

              • 4. Re: Prevent resource loading in a custom tag
                nbelaevski

                Can you please try 3.3.0.CR2?