3 Replies Latest reply on Dec 23, 2008 6:47 PM by nbelaevski

    a4j:support in custom component

    bitec

      Hello. I want to create custom component - select component with a4j:support functionality and 'clear' button to the right of this select tag. How I implemented this component:

      public class CleanableAjaxSelectOneMenu extends HtmlSelectOneMenu {
      ...
      
       private HtmlAjaxSupport support = new HtmlAjaxSupport();
      
       private HtmlAjaxCommandLink closeLink = new HtmlAjaxCommandLink();
      
       private HtmlGraphicImage closeImg = new HtmlGraphicImage();
      
       private UISelectItems selectItems = new UISelectItems();
      
       public CleanableAjaxSelectOneMenu() {
       // Here in parent we set the default render type for select.
       super();
      
       // Adding support as facet to the current component (none of ways works)
       this.getFacets().put("org.ajax4jsf.ajax.SUPPORTonchange", support);
       //this.getFacets().put("a4jsupport", support);
      
       // Adding empty select items component
       this.getChildren().add(selectItems);
      
       // Creating a4j command link for clearing icon
       closeLink.setAjaxSingle(true);
      
       closeLink.setLimitToList(true);
      
       closeLink.getChildren().add(closeImg);
      
       closeImg.setUrl(DEFAULT_IMG_URL);
       // Also some code for javascript clearing of select element and rerendering elements, specified for this select
       ...
       }
      
       public void encodeEnd(FacesContext context) throws IOException {
       // TODO why is 'support' facet not automatically rendered as onchange atribute for this select component??
       super.encodeEnd(context);
      
       // Some code for rerendering 'clean' button
       ...
       }
       }


      The problem with this code is that HtmlAjaxSupport is not being rendered for the current select component and no ' onchange="A4J.AJAX.Submit('table_form..."' html code was rendered, though I included it as the facet as the documentation advises:

      this.getFacets().put("org.ajax4jsf.ajax.SUPPORTonchange", support);


      I really could not find the way, how is '<a4j:support..>' tag is rendered for the component, to which it is attached and when the 'onchange' (for e.g.) atribute for select should be added during life cycle process of 'select' component. Any help is appreciated!

        • 1. Re: a4j:support in custom component
          nbelaevski

          Hello,

          Set support's event attribute.

          • 2. Re: a4j:support in custom component
            bitec

            I initialize all necessary properties in support using custom tag, so everything is initialized with the tag like this:

            <al:cleanableAjaxSelectOneMenu drawEmptyOption="true" event="onchange"
             value="#{orderFilterBean.filterCustomer}"
             binding="#{orderFilterBean.customersSelect}"
             id="filterCustomer"
             valueChangeListener="#{orderFilterBean.customerChanged}"
             selectItems="#{customerFilterStorage.selectData}"
             reRender="orderTable, filterContract"
             ajaxSingle="true" limitToList="true" />


            Here is the support field stack before the 'encodeEnd' is called (copied from Eclipse debug window, cut a bit):

            support HtmlAjaxSupport (id=202)
             _ajaxSingle true
             _ajaxSingleSet true
             _bypassUpdates false
             _bypassUpdatesSet false
             _disabledSet false
             _event "onchange" (id=210)
             _limitToList true
             _limitToListSet true
             _reRender JspValueExpression (id=219)
             actionExpression null
             attributes UIComponentBase$AttributesMap (id=225)
             attributesThatAreSet null
             bindings null
             children UIComponentBase$ChildrenList (id=227)
             clientId null
             facets UIComponentBase$FacetsMap (id=229)
             id null
             immediate null
             parent CleanableAjaxSelectOneMenu (id=143)
             pdMap HashMap<K,V> (id=1420)
             rendered true
             renderedSet false
             rendererType "org.ajax4jsf.components.AjaxSupportRenderer" (id=1421)
            


            • 3. Re: a4j:support in custom component
              nbelaevski

              Please take a look at this code: http://fisheye.jboss.org/browse/RichFaces/trunk/ui/core/src/main/java/org/ajax4jsf/component/UIAjaxSupport.java?r=9462 - setParent() method. Does setParent() executes before or after filling support with attributes in your case?