Search code examples
seamseam2seam3

DataModel and DataModelSelection in Seam3


I cannot seem to find where is @DataModel and @DataModelSelection in Seam3 (as opposed to Seam2). In what Seam module are they defined? If their name has been changed, what is it currently?


Solution

  • Assuming you are using JSF2.0, you can 'inject' selection to action methods like this:

    <h:dataTable value="#{itemManager.itemList}" var="item">
       <h:column>
          <f:facet name="header">Item Id</f:facet>
          #{item.id}
       </h:column>
       <h:column>
          <f:facet name="header">Item Name</f:facet>
          #{item.name}
       </h:column>
       <h:column>
          <f:facet name="header">Action</f:facet>
          <h:commandLink value="Delete" action="#{itemManager.delete(item)}" />
       </h:column>
    </h:dataTable>
    

    and corresponding managed bean:

    @ManagedBean(name="itemManager")
    @SessionScoped
    public class ItemManager {
        ArrayList<Item> itemList;
    
        public ArrayList<Item> getItemList() {
            if (itemList == null) {
                itemList = ... // build item list
            }
            return itemList;
        }
    
        public String delete(Item item) {
            itemList.remove(item);
            return null;
        }
    }