10 Replies Latest reply on Feb 21, 2010 8:56 AM by allforjava

    SelectManyCheckbox within rich:column

    allforjava

      Dear Team,

       

      The valueChangeLister (bean method) is not invoked when the checkbox value is toggles. Whatm'I missing?

       

      Following are the code snippet.

       

       

      <rich:column>

       

      <f:facet name="header">

       

      <ui:include src="/layout/sort.xhtml">

       

      <ui:param name="entityList" value="#{worksList}"/>

       

      <ui:param name="propertyLabel" value="Checklists"/>

       

      <ui:param name="propertyPath" value="works.checklists.id"/>

       

      </ui:include>

       

      </f:facet>

       

      <h:selectManyCheckbox value="#{worksList.selectedSheets}" valueChangeListener="#{worksList.updateChecklists}">

       

      <f:selectItems value="#{_works.checklists.fetchSheetsAsItems()}" />

       

      <s:convertEntity/>

       

      </h:selectManyCheckbox>

       

       

      </rich:column>

       

      And used with Seam Components & JPA entities

       

      @Name

       

      ("worksList")

      public

       

       

      class WorksList extends EntityQuery<Works> {

      ...

       

           public List<Sheets> getSelectedSheets() {

       

                return selectedSheets;

           }

       

       

           public void setSelectedSheets(List<Sheets> selectedSheets) {

       

                this.selectedSheets = selectedSheets;

           }

       

       

           public void updateChecklists(ValueChangeEvent event){

                System.

      out.println("ValueChanged:"+event);

           }

      }

       

      @Entity

      @

       

      Table(name = "AC_CHECKLISTS", schema = "ADR")

      public

       

       

      class Checklists implements java.io.Serializable {

       

          

           private Set<Sheets> sheets = new HashSet<Sheets>(0); //  with getter+setter

       

       

       

      ...

       

           @Transient

       

           public List<SelectItem> fetchSheetsAsItems(){

                Set<Sheets> hsSheets = getSheets();

       

                if(hsSheets == null){

                     System.

      out.println("Sheets are Empty ");

                     System.

      out.print("for '"+works.getNotes()+"' in "+works.getShifts().getDescription());

       

                     return null;

                }

       

       

                items = new ArrayList<SelectItem>(hsSheets.size());

                Time interval =

      new Time(30*60*1000);

                Time from =

      works.getShifts().getTimeFrom();

       

       

                for (Sheets sheets : hsSheets) {

                     SelectItem si =

      new SelectItem();

                     si.setValue(sheets);

       

                     items.add(si);

                     from =

      new Time(from.getTime()+interval.getTime());

                }

       

                return items;

           }

       

      }

                   

       

        • 1. Re: SelectManyCheckbox within rich:column
          nbelaevski

          Hi,

           

          h:selectManyCheckbox doesn't initiate server request by itself, so you can add a4j:support/a4j:commandButton to check if that's the reason

          • 2. Re: SelectManyCheckbox within rich:column
            allforjava

            Thank you Nick. I have tried that. However still the same problem. The modified code snippet.

             

            </rich:column>
            <h:selectManyCheckbox id="idMC_sheets">
              <s:selectItems  value="#{sheetsList.fetchSheetsFor(_works.checklists)}"
                var="sheet" itemValue="#{sheet}" label="#{sheet.id}"/>
               <a4j:support event="onclick" actionListener="#{sheetsList.toggleSheets}"/>
              <s:convertEntity/>
            </h:selectManyCheckbox>
            </rich:column>

             

            import javax.faces.event.ActionEvent;

            @Name("sheetsList")
            @Scope(ScopeType.CONVERSATION)
            public class SheetsList extends EntityQuery<Sheets> {

            private static final String[] RESTRICTIONS = {
              "sheets.checklists = #{sheetsList.sheets.checklists}", 
            };

            .
            .
            .

            @Begin(join=true)
            public List<Sheets> fetchSheetsFor(Checklists checklists){
              if(checklists == null){
               System.out.println("fetchSheetsFor(): No restriction");
              }
              getSheets().setChecklists(checklists);
              setMaxResults(null);
               List<Sheets> list = getResultList();
              setMaxResults(25);
              return list;
            }

            public void toggleSheets(ActionEvent event){
              System.out.println("Sheet Toggled!");
              System.out.println(event);
            }
            }

            • 3. Re: SelectManyCheckbox within rich:column
              ilya_shaikovsky
              please check with rich:message that there are no messages.
              • 4. Re: SelectManyCheckbox within rich:column
                allforjava

                HI Ilya,

                 

                The code got working after some modification. The h:form tags were missing. The code snippet is as http://www.seamframework.org/Community/ObjectRequiredCOnversationRelated#comment113675

                 

                However I'm nust sure to get the selected checkbox value/entity into the actionListener method. Any way with ActionEvent object?

                 

                Thank you in advance!

                • 5. Re: SelectManyCheckbox within rich:column
                  ilya_shaikovsky
                  At the moment when listener called - model alreay updated with submitted values. So just get the values from model. Or you could get  values(old and new one) from ValueChangeEvent object.
                  • 6. Re: SelectManyCheckbox within rich:column
                    allforjava

                    Hi Ilya,

                     

                    I'm using a4j:support wwith actionListener. The javax .. ActionEvent is fired. Any way to get the updated model with ajax support? If any code snippet will be helpful. Facing difficulty to find it. Or any tutorial or e-book?

                    • 7. Re: SelectManyCheckbox within rich:column
                      nbelaevski

                      Hi,

                       

                      Add this to page code:

                      <h:selectManyCheckbox value="#{sheetsList.selectedItems}">
                      

                      and "selectedItems" property in your bean.

                      • 8. Re: SelectManyCheckbox within rich:column
                        allforjava

                        Hi Nick,

                         

                        I guess I had not made very clear about what m'I expecting. I'll try for h:selectManyCheckbox using s:selectItems binding to set collection. Now when I use the a4j:support I wana capture the specific entity/modal object towards selected checkbox from the many. And update instantlly to database.

                         

                        I tried the way that u have suggested however in such I need to update the complete collection OR compare & then update.

                         

                        Any way I can fetch the object/modal from the ActionEvent specific to the selected/changed checkbox only.

                        • 9. Re: SelectManyCheckbox within rich:column
                          nbelaevski
                          Correct me if I'm wrong, you need to know what select item has been checked or unchecked? I don't think it's possible with h:selectManyCheckbox without comparing sets of selected items. 
                          1 of 1 people found this helpful
                          • 10. Re: SelectManyCheckbox within rich:column
                            allforjava
                            Yes, you are correct Nick. Finally I used ui:repeat and binded the each checkbox with an element in the collection. It worked as needed.