11 Replies Latest reply on Jul 12, 2006 2:35 PM by asaf sh

    selectBooleanCheckbox with a dataTable

    asaf sh Expert

      Hello,

      I have a datatable with a 'selectBooleanCheckbox' per row:

       <t:dataTable id="accountsForUserDataTableList"
       var="account"
       value="#{user.accounts}"
       >
       <h:column>
       <f:facet name="header">
       <h:outputText value="#{msgs.id}" />
       </f:facet>
       <h:outputText value="#{account.accountId}" />
       </h:column>
      
       <h:column>
       <f:facet name="header">
       <h:outputText value="Selected?" />
       </f:facet>
       <h:selectBooleanCheckbox value="#{accountSelection[account]"/>
       </h:column>
      
       </t:dataTable>
      <h:commandButton value="Delete..." action="#{userManager.delete}" class="button"/>
      
      



      I declared within one of my stateless bean a Map that corresponds to the value of the 'selectBooleanCheckbox' named 'accountSelection' as follows:

      @Out(scope=ScopeType.EVENT,required=false)
      Map<Account, Boolean> accountSelection;
      



      When the 'commandButton' is executed, nothing happens, the action is not called and nothing is written in server logs,

      at the moment I take off the 'selectBooleanCheckbox', or change its value to anything which is not multiple (does not include a '[]'), pressing on the button calls the action fine.


      What could be the reason for that? it seems that almost the same code is used in the dvdshop sample (while browsing the items) except that I do not use a conversation here...

      At least I'd like to know why the action is not called at all, I see the page getting refreshed but nothing happens :-/

      Thanks guys,
      Asaf.

        • 1. Re: selectBooleanCheckbox with a dataTable
          Pete Muir Master

          Often when an action method seems not to be called it is because an error occured in the JSF lifecycle BEFORE the INVOKE_APPLICATION phase (which is when the action method is called).

          Do you see in any errors (probably related to model update) in <h:messages />?

          • 2. Re: selectBooleanCheckbox with a dataTable
            asaf sh Expert

            Hey,

            Nothing, no errors in <h:messages/>, nothing at the backend (server logs), but as I said, it's for sure related to the checkboxes, no clue what...

            any way to debug such a situation? i'm clueless...


            thanks for answering :)

            Asaf.

            • 3. Re: selectBooleanCheckbox with a dataTable
              Gavin King Master

              Check the Seam startup log, to make sure that all your components are actually getting installed.

              • 4. Re: selectBooleanCheckbox with a dataTable
                asaf sh Expert

                Hey,
                I dont think this is the problem,

                the stateless bean is accessible ( I use a DataModel to display the dataTable where each of its rows is a checkbox ) and the methods are accessible, the problem -ONLY- occures when I use a 'selectBooleanCheckbox' where its value is an array! when the value is not an array the action is executed fine :-/

                Thanks

                • 5. Re: selectBooleanCheckbox with a dataTable
                  Gavin King Master

                  So then it sounds like a pure-jsf problem, nothing to do with Seam, right?

                  • 6. Re: selectBooleanCheckbox with a dataTable
                    asaf sh Expert

                    I'm not sure, but probably...

                    Is there any way to see if the Map i'm trying to set is really outjected?

                    Seems like JSF fails before the invoke-application phase if the property is not available...

                    This is the property in the Statless bean:

                    @Out(scope=ScopeType.EVENT,required=false)
                    Map<Account, Boolean> accountSelection;
                    


                    This is the code within the DataTable where 'var=account'

                     <h:selectBooleanCheckbox value="#{accountSelection[account]"/>
                    



                    Thanks.

                    • 7. Re: selectBooleanCheckbox with a dataTable
                      asaf sh Expert

                      Okay,

                      After spending some hours, I figured out that changing the following line in the facelets code:

                      <h:selectBooleanCheckbox value="#{accountSelection[account]}"/>
                      
                      


                      to:
                      <h:selectBooleanCheckbox value="#{userManager.accountSelection[account]}"/>
                      


                      made things work, submitting the form really call the action within the 'commandButton' component.


                      I just wonder what's wrong, as I said, I declared the 'accountSelection' variable within the 'userManager' EJB3 as:

                      @Out(required=false)
                      private Map<Account, Boolean> accountSelection;
                      


                      I didnt encapsulate it as seems like it's not required for Outjected vars,


                      So what's wrong? I'm almost sure the field is not outjected at all, this is the only difference between using the variable as outjected by SEAM and using it as a bean property.

                      How can I check if it's outjected at all? or maybe is it something else?


                      Thanks a lot,

                      Asaf.

                      • 8. Re: selectBooleanCheckbox with a dataTable
                        Pete Muir Master

                        Are you sure the accountSelection is not being outjected null? Do you have factory?

                        • 9. Re: selectBooleanCheckbox with a dataTable
                          asaf sh Expert

                          How can I know if it's outjected or not?

                          I dont have a factory, but on a previous function I call, I intiialize the Map to a HashMap....,

                          but two questions goes here:
                          1) How can I know what are the vlaues of the outjected vars? this is very important for debugging.
                          2) How can I know if the var is outjected as null?


                          Thanks

                          • 10. Re: selectBooleanCheckbox with a dataTable
                            Pete Muir Master

                            You said the bean is stateless up the thread. So that initialised value may well be lost (I think, I'm not 100% up at what stage in the lifecycle stateless beans are created/destroyed).

                            If the value is null it won't be outjected.

                            So,

                            1) Use the debugger (attached I think to the bijection interceptor)
                            2) Well if it is not null, you will see the Seam variable resolver find the context variable on the log. Or if you set required=true then Seam throw an exception if the value is null

                            • 11. Re: selectBooleanCheckbox with a dataTable
                              asaf sh Expert


                              Well, actually, if it's null then even calling it is a bean property would raise a null exception... so I assume the previous method which intiialize the Map to a Hashmap works....

                              More than that, is intiailizing the property while declaring it is for an outjected var? such as:

                              @Out(required=false)
                               private Map<Account, Boolean> accountSelection = new HashMap<Account,Boolean>();
                              


                              If so, then it doesnt work as well, submitting the form stays on the same form, no error is set and nothing happens.


                              thanks.