13 Replies Latest reply on Oct 2, 2006 7:55 PM by gavin.king

    DataModelSelection problem

    monkeyden

      I am currently displaying a search results screen, each of which has a link to a detail screen. Classic scenario. The selected row is to be injected into the backing bean, added to session and made available to the next screen.

      The problem is, the first row is always injected, no matter which I select on the client, despite the fact that each of the rows has unique ids assigned ("_id0:results_0:_id7", "_id0:results_1:_id7", "_id0:results_2:_id7", etc).


      Here is how I have the to-be-selected object defined in the backing bean:

      @Stateful
      @Scope(ScopeType.SESSION)
      @Name("usersearch")
      public class UserSearchAction implements UserSearch, Serializable {
      ...
       @DataModel
       @Out(required=false)
       private List<UserView> users;
      
       @DataModelSelection
       @In(required=false)
       @Out(scope=ScopeType.SESSION, required=false)
       private UserView user;
      ...
      }
      



      The action method just returns the next page in the flow.

      public String select() {
       return "refresh-page";
      }
      


      Thanks for the advice.

        • 1. Re: DataModelSelection problem
          pmuir

          Can you show your jsf?

          • 2. Re: DataModelSelection problem
            monkeyden

            Sure, sorry. I highlighted the commandLink of interest.

            <h:dataTable id="results" var="user" value="#{usersearch.items}" styleClass="resultsTable"
             rowClasses="odd,even" first="#{usersearch.firstRowIndex}" rows="#{usersearch.rowsPerPage}"
             rendered="#{usersearch.rowCount > 0}" headerClass="">
             <h:column>
             <f:facet name="header">
             <h:commandLink action="#{usersearch.sortByName}" immediate="true" styleClass="resultsHead">
             <h:outputText value="Name" id="nameText"/>
             </h:commandLink>
             </f:facet>
             <h:commandLink value="#{user.name}" action="#{usersearch.select}" immediate="true"/>
             </h:column>
             <h:column>
             <f:facet name="header">
             <h:commandLink action="#{usersearch.sortByEmail}" immediate="true" styleClass="resultsHead">
             <h:outputText value="Email"/>
             </h:commandLink>
             </f:facet>
             <h:commandLink id="emailLink">
             <h:outputText value="#{user.emailAddr}"/>
             </h:commandLink>
             </h:column>
             <h:column>
             <f:facet name="header">
             <h:commandLink action="#{usersearch.sortByDateRegistered}" immediate="true" styleClass="resultsHead">
             <h:outputText value="Registered"/>
             </h:commandLink>
             </f:facet>
             <h:outputText value="#{user.dateRegistered}" id="regText">
             <f:convertDateTime dateStyle="medium" pattern="MM/dd/yyyy"/>
             </h:outputText>
             </h:column>
             <h:column id="regColumn">
             <f:facet name="header">
             <h:outputText value="City" id="regText"/>
             </f:facet>
             <h:outputText value="#{user.city}" />
             </h:column>
             <h:column id="stateColumn">
             <f:facet name="header">
             <h:outputText value="State" />
             </f:facet>
             <h:outputText value="#{user.state}" />
             </h:column>
             <h:column>
             <f:facet name="header">
             <h:outputText value="Zip" />
             </f:facet>
             <h:outputText value="#{user.zip}" />
             </h:column>
            </h:dataTable>


            • 3. Re: DataModelSelection problem
              pmuir

              I don't know if this is the case, but I'm not sure that the DataModelSelection will be updated in immediate=true (and to me it seems unecessary on that page).

              • 4. Re: DataModelSelection problem
                pmuir

                 

                updated in immediate=true


                updated when immediate=true

                Sorry

                • 5. Re: DataModelSelection problem
                  monkeyden

                  Thanks for the reply. I removed the immediate attribute, to no avail. It appeared, however, that because the rows were uniquely named in the resulting JSP, that it should have worked regardless. As you might have gleaned from the JSF, I also implemented a paginator. FWIW, If I were to traverse the paginator, and select a row on a different page, it will also select that page's first row, and not the first row of the entire List.

                  • 6. Re: DataModelSelection problem
                    monkeyden

                    Is there any requirement of the client to pass a unique identifier back to the SB? Just a thought, though I saw nothing indicating this in the Messages tutorial.

                    • 7. Re: DataModelSelection problem
                      pmuir

                      I can't see a problem with what you are doing. It's quite simple, it should 'just work' using a JSF datatable and h:commandButton/Link.

                      I suggest the standard approach: start with a simple table with clickable links (see some of the examples), make sure it is working, and make your additions slowly and check to see where your problem is.

                      • 8. Re: DataModelSelection problem
                        monkeyden

                        I'm very doubtful that it's something on the JSF side. I removed every column with the exception of this one and it still didn't work. It seems pretty clear to me that there is an informational disconnect in the injection. Do all of my annotations appear correct?

                        @Stateful
                        @Scope(ScopeType.SESSION)
                        @Name("usersearch")
                        public class UserSearchAction implements UserSearch, Serializable {
                        ...
                         @DataModel
                         @Out(required=false)
                         private List<UserView> users;
                        
                         @DataModelSelection
                         @In(required=false)
                         @Out(scope=ScopeType.SESSION, required=false)
                         private UserView user;
                        ...
                        }
                        


                        Does anyone know of other examples to which I can refer?

                        • 9. Re: DataModelSelection problem
                          gavin.king

                          Don't use @DataModel with @Out.

                          Don't use @DataModelSelection with @In.

                          • 10. Re: DataModelSelection problem
                            gavin.king

                            ie. Look again at the examples.

                            • 11. Re: DataModelSelection problem
                              monkeyden

                              BINGO! Thanks Gavin.

                              Is the @Out incorrect in the tutorial as well?

                              @DataModel
                              private List<Message> messageList;
                              
                              @DataModelSelection
                              @Out(required=false)
                              private Message message;




                              • 12. Re: DataModelSelection problem

                                Is this ok?

                                @Out(value = "task", scope = ScopeType.SESSION)
                                 @DataModelSelection(value = "tasks")
                                 Task task;
                                


                                Btw, also is it "legal" to have @DataModelSelection in another SFSB than from where the @DataModel originated? It didn't work, atleast on my portlet environment where the sender (@DataModel) and the receiver (@DataModelSelection) were actually different on portlets (and also different SFSBs)... So i gave up and ended up passing the selections in the Session scope.



                                • 13. Re: DataModelSelection problem
                                  gavin.king

                                  You can use @Out with @DataModelSelection. Just like you can use @Out with @In.