5 Replies Latest reply on Jul 25, 2009 4:33 AM by Dave Ellery

    ScrollableDataTable DataModelSelection first row only

    Dave Ellery Newbie

      Seam: 2.2.0.CR1
      JBoss AS 4.2.3.GA


      So im using the ScrollableDataTable, and in my backing bean I setup a DataModel and DataModelSelection, however the selection is only ever set/injected as the first row in my table, regardless of the selection...


      table



      <rich:panel>
                                                                                                      <f:facet name="header">Ladders</f:facet>
                                                                                                      
                                                                                                      <h:form id="ladderTableFormId" >
                                                                                                              
                                                                                                              <rich:scrollableDataTable id="portalLadderTable"
                                                                                                                                                      rendered="#{portalHome.ladders.size > 0}"
                                                                                                                                                              value="#{portalAdminLadders}"
                                                                                                                                                              var="_ladder"
                                                                                                                                                              width="550px"
                                                                                                                                                              height="160px"
                                                                                                                                                       >    
                                                                                                                      <rich:column sortable="false" >
                                                                                                                      <f:facet name="header">Ladder Name</f:facet>
                                                                                                                      <h:outputText value="#{_ladder.ladderName}"/>
                                                                                                              </rich:column>                             
                                                                                                                      <rich:column sortable="false" >
                                                                                                                      <f:facet name="header">Game Name</f:facet>
                                                                                                                      <h:outputText value="#{_ladder.game.gameName}"/>
                                                                                                              </rich:column>
                                                                                                              <rich:column sortable="false" >
                                                                                                                      <f:facet name="header">Run No.</f:facet>
                                                                                                                       <h:outputText value="#{_ladder.run}"/>
                                                                                                              </rich:column>
                                                                                                                  <rich:column sortable="false" >
                                                                                                                      <f:facet name="header">Teams</f:facet>
                                                                                                                      <h:outputText value="#{_ladder.ladderTeams.size}"/>
                                                                                                                  </rich:column>
                                                                                                                                                                                                                      </rich:scrollableDataTable>
                                                                                                              <div class="actionButtons">
                                                                                                      
                                                                                                              <a:commandButton              
                                                                                                                                                              id="portalLadderEditId"    
                                                                                                                                                       action="#{portalAdmin.takeLadderSelection}" 
                                                                                                                                                        value="Edit"
                                                                                                                                                 reRender="ladderNameField,ladderGameField"
                                                                                                                                                  />
                                                                                                                                                
                                                                                                      </div>
                                                                                                      </h:form>
                                                                                                      
                                                                                              </rich:panel>




      the backing bean



      @Name("portalAdmin")
      @Scope( ScopeType.PAGE )
      public class PortalAdmin {
              
              @In PortalHome portalHome;
              
              @In LadderHome ladderHome;
      
              
              @DataModel( value="portalAdminLadders", scope=ScopeType.PAGE )
              List<Ladder> portalLadders;
              
              @DataModelSelection( "portalAdminLadders" )
              @Out( required=false )
              private Ladder selectedLadder;
              
              
              public void takeLadderSelection(){
                      if( this.selectedLadder != null ){
                              
                              System.out.println( "selected ladder: " + this.selectedLadder.getLadderName() );
                              this.ladderHome.setInstance( this.selectedLadder );
                      } else {
                              this.ladderHome.clearInstance();
                      }
              }




      I have been playing with the scope, but it doesnt change anything so im kind of at my wits end here







        • 1. Re: ScrollableDataTable DataModelSelection first row only
          Dave Ellery Newbie

          sorry, properly formatted table



          <rich:panel>
               <f:facet name="header">Ladders</f:facet>
                                                                                                          
               <h:form id="ladderTableFormId" >
                                                                                                                  
                     <rich:scrollableDataTable id="portalLadderTable"
                              rendered="#{portalHome.ladders.size > 0}"
                              value="#{portalAdminLadders}"
                              var="_ladder"
                              width="550px"
                              height="160px"
                                   >    
                         <rich:column sortable="false" >
                              <f:facet name="header">Ladder Name</f:facet>
                              <h:outputText value="#{_ladder.ladderName}"/>
                         </rich:column>                             
                         <rich:column sortable="false" >
                              <f:facet name="header">Game Name</f:facet>
                              <h:outputText value="#{_ladder.game.gameName}"/>
                         </rich:column>
                         <rich:column sortable="false" >
                              <f:facet name="header">Run No.</f:facet>
                              <h:outputText value="#{_ladder.run}"/>
                         </rich:column>
                         <rich:column sortable="false" >
                              <f:facet name="header">Teams</f:facet>
                              <h:outputText value="#{_ladder.ladderTeams.size}"/>
                         </rich:column>
                    </rich:scrollableDataTable>
                    <div class="actionButtons">
                                                                                                          
                         <a:commandButton              
                                    id="portalLadderEditId"    
                                    action="#{portalAdmin.takeLadderSelection}" 
                                 value="Edit"
                                 reRender="ladderNameField,ladderGameField"
                                />
                                                                                                                                                    
                    </div>
               </h:form>
                                                                                                          
          </rich:panel>




          • 2. Re: ScrollableDataTable DataModelSelection first row only
            Dave Ellery Newbie

            Im going to try upgrading to JBoss AS 5.0.1.GA, though i doubt that will make any difference :(

            • 3. Re: ScrollableDataTable DataModelSelection first row only
              Sylvain Catudal Newbie

              I don't think it's meant to be used like this.


              Try this as an example :


              <rich:panel>
                   <f:facet name="header">Ladders</f:facet>
                                                                                                              
                   <h:form id="ladderTableFormId" >
                                                                                                                      
                         <rich:scrollableDataTable id="portalLadderTable"
                                  rendered="#{portalHome.ladders.size > 0}"
                                  value="#{portalAdminLadders}"
                                  var="_ladder"
                                  width="550px"
                                  height="160px"
                                       >    
                             <rich:column sortable="false" >
                                  <f:facet name="header">Ladder Name</f:facet>
                                  <h:outputText value="#{_ladder.ladderName}"/>
                             </rich:column>                             
                             <rich:column sortable="false" >
                                  <f:facet name="header">Game Name</f:facet>
                                  <h:outputText value="#{_ladder.game.gameName}"/>
                             </rich:column>
                             <rich:column sortable="false" >
                                  <f:facet name="header">Run No.</f:facet>
                                  <h:outputText value="#{_ladder.run}"/>
                             </rich:column>
                             <rich:column sortable="false" >
                                  <f:facet name="header">Teams</f:facet>
                                  <h:outputText value="#{_ladder.ladderTeams.size}"/>
                             </rich:column>
                             <rich:column sortable="false" >
                                  <f:facet name="header">Action</f:facet>
                                  <a:commandButton              
                                             id="portalLadderEditId"    
                                             action="#{portalAdmin.takeLadderSelection}" 
                                          value="Edit"
                                          reRender="ladderNameField,ladderGameField"
                                         />
                             </rich:column>
                        </rich:scrollableDataTable>
                   </h:form>
              </rich:panel>
              



              From what I understand, the @DataModelSelection will have Seam inject the object that corresponds(in the DataModel) to the index of the clicked row.


              If you want to stick with one button bellow your datatable, you have to use the selection attribute on the scrollableDataTable and bind it to a property in your backing bean.  Example :


              @Name("portalAdmin")
              @Scope( ScopeType.PAGE )
              public class PortalAdmin {
                      
                      @In PortalHome portalHome;
                      
                      @In LadderHome ladderHome;
              
                      
                      @DataModel( value="portalAdminLadders", scope=ScopeType.PAGE )
                      List<Ladder> portalLadders;
                      
              
              
                   private Selection selection;
                           
                   public Selection getSelection() {
                        return selection;
                   }
              
                   public void setSelection( Selection selection ) {
                        this.selection = selection;
                   }
              
                      public void takeLadderSelection(){
                              if( this.selectedLadder != null ){
                                      
                                      System.out.println( "selected ladder: " + this.selectedLadder.getLadderName() );
                                      this.ladderHome.setInstance( this.selectedLadder );
                              } else {
                                      this.ladderHome.clearInstance();
                              }
                      }
              



              You then set the 'selection' attribute of the scrollableDataTable:


              <rich:scrollableDataTable id="portalLadderTable"
                                  rendered="#{portalHome.ladders.size > 0}"
                                  value="#{portalAdminLadders}"
                                  var="_ladder"
                                  width="550px"
                                  height="160px"
                                  selection="#{portalAdmin.selection}">  
              



              You also have to change the implementation of your takeLadderSelection method:


                      public void takeLadderSelection(){
                        Ladder l = null;
              
                        for( Iterator<Object> iterator = selection.getKeys(); iterator.hasNext(); )           {
                             Integer index = (Integer)iterator.next();
                             l = portalLadders.get( index );
                        }                        
                              if( l != null ){
              
                                      System.out.println( "selected ladder: " + l.getLadderName() );
                                      this.ladderHome.setInstance( l );
                              } else {
                                      this.ladderHome.clearInstance();
                              }
                      }
              



              I hope that helps.


              Sylvain

              • 4. Re: ScrollableDataTable DataModelSelection first row only
                Dave Ellery Newbie
                ok excellent, will try it out once i get home tonight.

                I had assumed that binding & selection were meant to be used exclusively from @DataModel & @DataModelSelection.