2 Replies Latest reply on Oct 8, 2008 6:51 AM by Anders Norgaard

    HtmlSelectOneMenu and HtmlAjaxSupport in java code

    Lukasz Grden Newbie

      I'm having some problems with the HtmlSelectOneMenu combined with HtmlAjaxSupport. In my application, I am using method bindings so I need to create and build up the UI Components in Java code.

      I have two HtmlSelectOneMenus. The first one (let's call it type) has statically assigned items. The second one (let's call it subtype) is dynamically filled based on the selected type.

      The problem I'm having is as the type changes the subtype is not re-rendered (refilled with new values). I debugged the code and both of the comboboxes are bound properly, values and id's are set properly as well. Below you can find the Java code snippet that is supposed to re-render the second (subtype) combobox.

      HtmlSelectOneMenu comboboxType = new HtmlSelectOneMenu();
      comboboxType.setId("type");
      
      HtmlAjaxSupport ajaxSupportType = new HtmlAjaxSupport();
      comboboxType.getFacets().put("a4jsupport", ajaxSupportType);
      
      HtmlSelectOneMenu comboboxSubType = new HtmlSelectOneMenu();
      comboboxSubType.setId("subtype");
      
      // value expressions are not shown...
      
      ajaxSupportType.setEvent("onchange");
      ajaxSupportType.setReRender(comboboxSubType.getClientIdFacesContext.getCurrentInstance()));
      ajaxSupportType.setAjaxSingle(true);
      
      


      Would anyone see/know what the problem is and suggest a solution?

      Thank you for the reply.

        • 1. Re: HtmlSelectOneMenu and HtmlAjaxSupport in java code
          Tsikhon Kuprevich Newbie

          Hi,

          thank you for your information. I've created an issue — https://jira.jboss.org/jira/browse/RF-4574

          • 2. Re: HtmlSelectOneMenu and HtmlAjaxSupport in java code
            Anders Norgaard Newbie

            Hi, I had almost the same problem. My solution was to use rich:suggestionbox and a4j:support. I am not sure this is the optimal solution. You can tell me what you think.

            The idea is that the cpeModel depends on which cpeVendor has been selected.

             <h:panelGrid columns="2" border="0" cellpadding="0" cellspacing="0">
             <h:inputText required="false" value="#{cpevendor.name}" id="cpevendornameInput" onfocus="#{rich:component('fwvendorsuggestion')}.callSuggestion(true)"/>
             <h:graphicImage value="/img/arrow.png" onclick="#{rich:component('fwvendorsuggestion')}.callSuggestion(true)"/>
             </h:panelGrid>
             <rich:suggestionbox for="cpevendornameInput" suggestionAction="#{firmwaremanager.autocompleteVendor()}" var="vendor" id="fwvendorsuggestion">
             <h:column>
             <h:outputText value="#{vendor.name}"/>
             </h:column>
             <a4j:support event="onselect" action="#{firmwaremanager.setCpeVendor(vendor)}">/a4j:support>
             </rich:suggestionbox>
             <h:panelGrid columns="2" border="0" cellpadding="0" cellspacing="0">
             <h:inputText required="false" value="#{cpemodel.model}" id="cpemodelnameInput" onfocus="#{rich:component('fwmodelsuggestion')}.callSuggestion(true)"/>
             <h:graphicImage value="/img/arrow.png" onclick="#{rich:component('fwmodelsuggestion')}.callSuggestion(true)"/>
             </h:panelGrid>
             <rich:suggestionbox for="cpemodelnameInput" suggestionAction="#{firmwaremanager.autocompleteModel()}" var="model" id="fwmodelsuggestion">
             <h:column>
             <h:outputText value="#{model.model}"/>
             </h:column>
             <a4j:support event="onselect" action="#{firmwaremanager.setCpeModel(model)}"></a4j:support>
             </rich:suggestionbox>
            

            (some formatting removed, to make the code more clear)


            Best,
            Anders