2 Replies Latest reply on Jan 18, 2011 11:23 AM by Peter Schütt

    Get click on h:selectOneListbox in BackingBean

    Peter Schütt Newbie

      Hallo,

      I am migrating from Richfaces 3.3.x to 4.0 (20101226)

       

      I have a listbox of values and I want to call a setter in the backend bean if the selection is changed.

       

      My old working solution was:

       

        <h:selectOneListbox id="waitingTaskInfos" value="#{userProcessingBean.selectedWaitingTaskId}"

                  style="height:15em;min-width:15em">

             <a4j:support event="onclick" render="waitingTaskInfos, otherControl">

                   <a4j:actionParam value="this.value" assignTo="#{userProcessingBean.selectedWaitingTaskId}"

                                                               name="selectedWaitingTask" noEscape="true"/>

            </a4j:support>

            <f:selectItems value="#{userProcessingBean.waitingTaskItems}"  />

        </h:selectOneListbox>

       

      Waiting-Task-Items are of the type java.util.List<javax.faces.model.SelectItem>.

      The value of SelectItem contains a String-ID.

      The setter is setSelectedWaitingTaskId.

       

      I changed to:

       

        <h:selectOneListbox id="waitingTaskInfos" value="#{userProcessingBean.selectedWaitingTaskId}"

                  style="height:15em;min-width:15em">

             <a4j:ajax event="click" render="waitingTaskInfos, otherControl">

                   <a4j:param value="this.value" assignTo="#{userProcessingBean.selectedWaitingTaskId}"

                                                               name="selectedWaitingTask" noEscape="true"/>

            </a4j:support>

            <f:selectItems value="#{userProcessingBean.waitingTaskItems}"  />

        </h:selectOneListbox>

       

      This does not work. I also did not find an example to use h:selectOneListbox with a4j somewhere.

       

      Thanks for any hint.

       

      Ciao

        Peter Schütt

        • 1. Get click on h:selectOneListbox in BackingBean
          Ilya Shaikovsky Master

          From the beginning I'm not sure such construction has sence...

            <h:selectOneListbox id="waitingTaskInfos" value="#{userProcessingBean.selectedWaitingTaskId}"

                      style="height:15em;min-width:15em">

                 <a4j:support event="onclick" render="waitingTaskInfos, otherControl"/>

            </h:selectOneListbox>

          and

            <h:selectOneListbox id="waitingTaskInfos" value="#{userProcessingBean.selectedWaitingTaskId}"

                      style="height:15em;min-width:15em">

                 <a4j:ajax event="click" render="waitingTaskInfos, otherControl"/>

            </h:selectOneListbox>

          this code already means that new values will be populated to selectedWaitingTaskId.. so see no reason to use additional setting using parameter.

          If you had any problems and just workarounded them in that way - it's better to make one step backward and solve original problems instead of using additional parameters.

          • 2. Get click on h:selectOneListbox in BackingBean
            Peter Schütt Newbie

            Hallo,

            thanks for your hint. It was easier than I thought.

             

            <h:selectOneListbox id="waitingTaskInfos" value="#{userProcessingBean.selectedWaitingTaskId}"

                       style="height:15em;min-width:15em">

                   <a4j:ajax event="click" render="waitingTaskInfos,otherControl">

                   </a4j:ajax>

                  <f:selectItems value="#{userProcessingBean.waitingTaskItems}"  />

            </h:selectOneListbox>

             

            This works.

             

            Ciao

              Peter Schütt