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

    a4j:support in custom component

    Anton Lisovenko Newbie

      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!