1 Reply Latest reply on Jun 15, 2009 9:04 AM by mpickell

    Richfaces 3.1.6 - Using HtmlAjaxSupport inside the bean

    m_w_abdo

      Hello,
      My screen generated dynamically contains two combo boxes "Country" and "City". Once you select a country the City combo box should change to show only the cities inside the chosen country.

      I have to use Richfaces 3.1.6 (JSF 1.1) because I have OC4J.

      The following block from my web page:

       <a4j:form ajaxSubmit="true" >
       <rich:panel>
       <h:panelGrid binding="#{MyBean.htmlPanelGrid}" />
       </rich:panel>
       </a4j:form>
      


      The following my bean code:
       public class MyBean {
       private HtmlPanelGrid htmlPanelGrid;
       private HtmlSelectOneMenu country;
       private HtmlSelectOneMenu city;
      
       // Normal setter/getter
      
       // Constructor
       public MyBean() {
       htmlPanelGrid = new HtmlPanelGrid();
      
       country = new HtmlSelectOneMenu();
      
       country.getChildren().add(createSelectItem("Jordan", "Jordan"));
       country.getChildren().add(createSelectItem("Egypt", "Egypt"));
      
       city = new HtmlSelectOneMenu();
      
       city.getChildren().add(createSelectItem("Amman", "Amman"));
       city.getChildren().add(createSelectItem("Cairo", "Cairo"));
      
       HtmlAjaxSupport htmlAjaxSupport = new HtmlAjaxSupport();
      
       htmlAjaxSupport.setEvent("onchange");
       htmlAjaxSupport.setReRender("city");
      
       htmlAjaxSupport.setActionListener(
       FacesContext.getCurrentInstance()
       .getApplication().createMethodBinding
       ("#MyBean.loadCombo}", null));
      
       country.getFacets().put("ajaxSupport", htmlAjaxSupport);
      
       this.getHtmlPanelGrid().getChildren().add(country);
       this.getHtmlPanelGrid().getChildren().add(city);
      }
      
      public void loadCombo() {
       System.out.println("i am working...");
      }
      


      There is no errors, but the loadCombo() method is not called by the AjaxSupport?

        • 1. Re: Richfaces 3.1.6 - Using HtmlAjaxSupport inside the bean
          mpickell

          I notice two things here:

          1) you are adding "city" as the re-render id. from this code, "city" is the field name, not the ID. It doesn't look like you are setting an ID to the "city" component.

          2) I'm not sure if you can do it both ways or not, but i would add the HtmlAjaxSupport as a child of "country" and not a facet.

          hope it helps.