8 Replies Latest reply: May 19, 2008 1:57 PM by Shervin Asgari RSS

    Where is selected=true on s:selectItems ?

    Shervin Asgari Master

      <h:selectManyCheckbox rendered="#{proeveTypeSokList != null and proeveTypeSokList.size > 0}">
           <s:selectItems value="#{proeveTypeSokList}" var="proevetype" label="#{proevetype.beskrivelse}" selected="true"/>
      </h:selectManyCheckbox>




      The code above does not work. How can I set selected to true as we could do the old days?
      I want the checkboxes to be default on.


      Thanks in advance

        • 1. Re: Where is selected=true on s:selectItems ?
          Stephen Friedrich Novice

          Not really a Seam question, but anyway:
          The selectItems tag is only used to specify the complete set of items (selected plus unselected).


          You specify the selected subset by using the value attribute of the selectManyCheckbox.


          Google for examples.

          • 2. Re: Where is selected=true on s:selectItems ?
            Nicklas Karlsson Master

            Haven't used selectManyCheckbox in a while but probably it's selected when the items value matches the value of target binding (which you don't have on your tag)

            • 3. Re: Where is selected=true on s:selectItems ?
              Shervin Asgari Master

              Huh? Im not sure what you mean here.


              The items value matches value of the target binding? Could you please explain how I do this?

              • 4. Re: Where is selected=true on s:selectItems ?
                Shervin Asgari Master

                Huh? Im not sure what you mean here.


                The items value matches value of the target binding? Could you please explain how I do this?

                • 5. Re: Where is selected=true on s:selectItems ?
                  Shervin Asgari Master

                  Stephen Friedrich wrote on May 16, 2008 09:14 PM:


                  Not really a Seam question, but anyway:
                  The selectItems tag is only used to specify the complete set of items (selected plus unselected).

                  You specify the selected subset by using the value attribute of the selectManyCheckbox.

                  Google for examples.


                  I have googled and googled, but no examples shows me a selectManyCheckBox that is default selected. The selectManyCheckbox does not take a selected as an attribute.
                  How can I use the value attribute to make it selected?

                  • 6. Re: Where is selected=true on s:selectItems ?
                    Stephen Friedrich Novice

                    <h:selectManyCheckbox rendered="#{proeveTypeSokList != null and proeveTypeSokList.size > 0}" value="#{aListOfAllSelectedElementsThisWillBeInititiallyReadFromToDetermineTheDefaultSelectionAndTheNewSelectionWillBeWrittenToItWhenTheFormIsSubmitted}">
                         <s:selectItems value="#{proeveTypeSokList}" var="proevetype" label="#{proevetype.beskrivelse}"/>
                    </h:selectManyCheckbox>


                    • 7. Re: Where is selected=true on s:selectItems ?
                      Shervin Asgari Master

                      Thank you Stephen. That did it.

                      • 8. Re: Where is selected=true on s:selectItems ?
                        Shervin Asgari Master

                        I got the result I wanted now, but I have one problem which I need help with...


                        My xhmtl now looks like this:



                        <h:selectManyCheckbox value="#{provetypeSelectedList}">
                        <s:selectItems value="#{proevetypeSokList}" var="proevetype" label="#{proevetype.beskrivelse}"/>
                        </h:selectManyCheckbox>
                        
                        <h:commandButton id="findProever" value="Find Proeve" action="#{searchRegisterManager.find}" reRender="searchResults" />



                        The provetypeSelectedList and proevetypeSokList contain the same values since I wanted all the elements in the checkbox  to be default set.


                        My action looks like this:



                        @Out(required=false)
                        private List<Proevetype> proevetypeSokList;
                             
                        @Out(required=false)
                        private List<Proevetype> provetypeSelectedList;
                        
                        @Factory(value= "proevetypeSokList")
                        public void findProevetyper() {
                             proevetypeSokList = em.createQuery("from " + Proevetype.class.getName() + " pt ").getResultList();
                        }
                             
                        @Factory(value= "provetypeSelectedList")
                        public void findProevetypeSelected() {
                             provetypeSelectedList = em.createQuery("from " + Proevetype.class.getName() + " pt ").getResultList();
                        }
                        
                        public void find() {
                        for (Proevetype pt : provetypeSelectedList) {
                           System.out.println("Value of pt: " + pt.getId());
                        }
                        }




                        Now the problem is that if you uncheck some of the values from the checkbox and submit the form, it still retrieves the whole list, but not the ones I selected.
                        What am I doing wrong here?