5 Replies Latest reply on Jul 10, 2007 4:47 AM by bram_

    Multiple Seam DataModelSelection in one action: Selection do

    bram_

      Hi,

      We have an abstract action to select the current object using DataModel
      and DataModelSelection annotation.

      For some reason we need a secondary list/current in the same action,
      so I added this in the ActionImpl including a specific name:

      @DataModel(value = "organizationalLevelConnections")
      private Collection<OrganizationalLevel> organizationalLevels;
      
      @DataModelSelection(value = "organizationalLevelConnections")
      private OrganizationalLevel currentOrganizationalLevel;
      


      I've also added names to the annotations of the generic list/current:
      @DataModelSelection(value = "searchResults")
      protected T current;
      
      @DataModel(value = "searchResults")
      protected Collection<T> searchResults;
      

      Now all the standard List/Current and the secondary list/current won't
      correctly selec, including all list/current datamodels in all other action-classes, because these extend the AbstractAction.
      Both have been named, both have public accessors.

      Can anyone tell me what I'm doing wrong?
      An example with selection and multiple (named?) DataModel(Selection)
      annotations in the same class would be helpful.

      Thanks

        • 1. Re: Multiple Seam DataModelSelection in one action: Selectio
          bram_

          Just to be clear:
          If I select any object from the list, the first object is always injected into current.

          • 2. Re: Multiple Seam DataModelSelection in one action: Selectio
            bram_

            I've tried to go back to only using single DataModel(Selection) pairs, but this also didn;t work anymore. I've found out that this doesn't work (in my page):

            <rich:dataTable id="myRequestsDataTable" var="result"
            value="#{investmentAction.searchResults}" rows="10">
            

            but this does work:
            <rich:dataTable id="myRequestsDataTable" var="result"
            value="#{searchResults}" rows="10">
            


            • 3. Re: Multiple Seam DataModelSelection in one action: Selectio
              bram_

              This works a lot better for the abstract DataModel:

              @DataModelSelection("searchResults")
              protected T current;
              
              @DataModel
              protected List<T> searchResults;
              


              I'm now gonna try the same for the secondary model.
              I'm still interested in a tutorial / example on how the DataModel and DataModelSelection annotations work
              in multiples like above, so if someone has a clear example / doc / tutorial, please post.

              • 4. Re: Multiple Seam DataModelSelection in one action: Selectio
                pmuir

                Can you post the whole page/bean (working, but remove any irrelevant fields/methods from then).

                • 5. Re: Multiple Seam DataModelSelection in one action: Selectio
                  bram_

                  This is the working code:

                  Abstract class:

                  package com.nxp.cda.commons.controller;
                  
                  import java.math.BigDecimal;
                  ...
                  import org.jboss.seam.annotations.datamodel.DataModel;
                  import org.jboss.seam.annotations.datamodel.DataModelSelection;
                  ...
                  import com.nxp.cda.commons.model.DomainObject;
                  public abstract class AbstractSearchAction<T extends DomainObject> implements
                   SearchAction<T> {
                  /**Current (selected) object */
                  @DataModelSelection("searchResults")
                  @Out(required = false)
                  protected T current;
                  
                  /**Resultset.*/
                  @DataModel
                  protected List<T> searchResults;
                  
                  public List<T> getSearchResults() {
                   return this.searchResults;
                  }
                  
                  protected void setSearchResults(List<T> searchResults) {
                   this.searchResults = searchResults;
                  }
                  
                  public T getCurrent() {
                   return current;
                  }
                  
                  public void setCurrent(T current) {
                   this.current = current;
                  }
                  
                  }
                  


                  And the specific implementation:
                  package com.nxp.atinvestor.web.controller;
                  
                  ...
                  import org.jboss.seam.annotations.datamodel.DataModel;
                  import org.jboss.seam.annotations.datamodel.DataModelSelection;
                  
                  import com.nxp.atinvestor.domain.Investment;
                  import com.nxp.atinvestor.domain.OrganizationalLevel;
                  import com.nxp.atinvestor.domain.User;
                  import com.nxp.cda.commons.controller.AbstractAction;
                  ...
                  
                  @Stateful
                  @Name("userAction")
                  @Scope(ScopeType.SESSION)
                  public class UserActionImpl extends AbstractAction<User>
                  implements UserAction {
                  
                   /** The current user: */
                   private User user;
                   /** All OrganizationalLevels that this user is an approver of. */
                   // This is the secondary model:@DataModel
                   private List<OrganizationalLevel> organizationalLevels;
                  
                   // This is the secondary model selected item:@DataModelSelection("organizationalLevels")
                   private OrganizationalLevel currentOrganizationalLevel;
                  
                   public List<OrganizationalLevel> getOrganizationalLevels() {
                   return organizationalLevels;
                   }
                  
                   public void setOrganizationalLevels(
                   List<OrganizationalLevel> organizationalLevels) {
                   this.organizationalLevels = organizationalLevels;
                   }
                  
                  
                   public OrganizationalLevel getCurrentOrganizationalLevel() {
                   return currentOrganizationalLevel;
                   }
                  
                   public void setCurrentOrganizationalLevel(
                   OrganizationalLevel currentOrganizationalLevel) {
                   this.currentOrganizationalLevel = currentOrganizationalLevel;
                   }
                  
                  }