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();
      HtmlAjaxSupport ajaxSupportType = new HtmlAjaxSupport();
      comboboxType.getFacets().put("a4jsupport", ajaxSupportType);
      HtmlSelectOneMenu comboboxSubType = new HtmlSelectOneMenu();
      // value expressions are not shown...

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

      Thank you for the reply.

        • 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)"/>
           <rich:suggestionbox for="cpevendornameInput" suggestionAction="#{firmwaremanager.autocompleteVendor()}" var="vendor" id="fwvendorsuggestion">
           <h:outputText value="#{vendor.name}"/>
           <a4j:support event="onselect" action="#{firmwaremanager.setCpeVendor(vendor)}">/a4j:support>
           <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)"/>
           <rich:suggestionbox for="cpemodelnameInput" suggestionAction="#{firmwaremanager.autocompleteModel()}" var="model" id="fwmodelsuggestion">
           <h:outputText value="#{model.model}"/>
           <a4j:support event="onselect" action="#{firmwaremanager.setCpeModel(model)}"></a4j:support>

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