6 Replies Latest reply on Jul 24, 2009 4:16 PM by jamesjmp

    SelectOneListBox strange behavior

    yasudevil

      Hi,


      I'm having a strange behavior in my page.


      I have a Entity that has a set as a parameter. Something like this.


      @Name("User")
      class User {
         Set<Car> cars;
      }



      On my page the set of childrens are represented as a Select listbox



      <h:selectOneListbox>
           <s:selectItems value="#{user.cars}"
                var="_car" label="#{_car.name}" itemValue="#{_child}"/>
      </h:selectOneListbox>



      I input new cars on a input text box, click on Add button that triggers a action, and set a new car on the User object.


      When I click add, the select box auto updates and the added value appears on my select box.


      To remove a car I select the car on my select, call a action and removes it from the set on the User object. But in this call the select box doesn't updates.


      All my buttons are


      <a4j:commandLink action"#{myAction.addCar}">
      <a4j:commandLink action"#{myAction.removeCar}">
      



      Sometimes when I add a new car the same happens, the object is inserted on my collection but the object on-screen does not shows it.


      For testing purposes I created another commandLink but without a action, when I click the new link the select box updates and shows the newly added Car or removes the previously removed Car.


      I tried to put a a4j:outputPanel outside my select box and then put the outputPanel id as a reRender param on mine commandLink.


        • 1. Re: SelectOneListBox strange behavior
          francisco.affonso

          Hi Diego,


          try something like:


          <h:selectOneListbox id="someSelect">
               <s:selectItems value="#{user.cars}"
                    var="_car" label="#{_car.name}" itemValue="#{_child}"/>
          </h:selectOneListbox>




          <a4j:commandLink reRender="someSelect" action"#{myAction.addCar}">
          <a4j:commandLink reRender="someSelect" action"#{myAction.removeCar}">
          


          • 2. Re: SelectOneListBox strange behavior
            yasudevil

            Hi Francisco,


            I tried that and I have the exact same behavior.


            I was thinking if it was possible that on reRender time the selected object was not removed from the collection.


            But, if that is the case for what reason when I add a object the field is updated correctly.

            • 3. Re: SelectOneListBox strange behavior
              yasudevil

              I've just realized that the combo isn't auto updated because I'm selecting one of the fields of my Select.


              Is there any option that I can force the reRender? It may be a desired behavior in some cases but for this one it's really annoying.

              • 4. Re: SelectOneListBox strange behavior
                roanbrasil

                Francisco,


                I am having a problem with a4j. I am getting 'A4J' is undefined.

                • 5. Re: SelectOneListBox strange behavior

                  Roan, check that you have defined a4j in your page composition
                  For example:


                  <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                      xmlns:s="http://jboss.com/products/seam/taglib"
                      xmlns:ui="http://java.sun.com/jsf/facelets"
                      xmlns:f="http://java.sun.com/jsf/core"
                      xmlns:h="http://java.sun.com/jsf/html"
                      xmlns:a4j="http://richfaces.org/a4j"
                      xmlns:rich="http://richfaces.org/rich"
                      template="layout/template.xhtml">
                  




                  Maybe you have



                      xmlns:a="http://richfaces.org/a4j"
                  






                  instead of
                    

                   
                      xmlns:a4j="http://richfaces.org/a4j"
                  


                  • 6. Re: SelectOneListBox strange behavior

                    Diego, to force a rerender when you select one of your items try this:



                    
                    <h:selectOneListbox id="someSelect">
                         <s:selectItems value="#{user.cars}"
                              var="_car" label="#{_car.name}" itemValue="#{_child}"/>
                    <a4j:support event="onchange"
                    
                    reRender="someSelect" ajaxSingle="true" />
                    </h:selectOneListbox>



                    Good luck!