4 Replies Latest reply on Oct 16, 2007 10:40 AM by Chris Hane

    Trinidad/TreeTable and how to determine selected rows

    Chris Hane Novice

      I am using the Trinidad TreeTable component. We present the component and the user can select a number of rows. When an commandButton is selected, we are trying to figure out a good way to get the selected rows in our method call.

      Here's what we have:

      Facelets fragment

      
       <tr:form id="frm">
       <tr:messages/>
      
       <tr:panelHorizontalLayout>
       <f:facet name="separator"><tr:spacer width="8px"/></f:facet>
       <tr:panelHeader text="Courses">
       <tr:panelButtonBar>
       <tr:commandButton text="Save" action="#{lister.save}" id="btn_save"/>
       </tr:panelButtonBar>
       </tr:panelHeader>
      
       </tr:panelHorizontalLayout>
       <tr:treeTable var="foo"
       value="#{lister.tree}"
       rowSelection="multiple"
       selectionListener="#{lister.selectionBindingMethod}">
       <f:facet name="nodeStamp">
       <tr:column>
       <f:facet name="header">
       <tr:outputText value="Name"/>
       </f:facet>
       <tr:outputFormatted value="#{foo.name} : #{foo.type} : #{foo.id}"/>
       </tr:column>
       </f:facet>
      
       </tr:treeTable>
       </tr:form>
      


      And the Seam component is:
      @Name("lister")
      @Stateful
      @LoggedIn
      public class CourseLister implements ICourseLister {
      
       TransferObject root;
       private TreeModel tree;
      
       public String save(){
       System.out.println("SAVE DONE>>>>");
       return null;
       }
      
       public String showCourses(){
       //<snip creation of a transfer object that contains the tree/>
      
       //convert the root object into a Trinidad TreeModel
       tree = new ChildPropertyTreeModel(root, "children");
      
       return "viewList";
       }
      
       public void selectionBindingMethod(SelectionEvent event){
       System.out.println("selectionBindingMethod["+event+"]");
      
       UIXCollection table = (UIXCollection)event.getSource();
      
       for(Iterator<Object> i = ((UIXTree)table).getSelectedRowKeys().iterator(); i.hasNext(); ){
       Object n = i.next();
       AppUtils.LOG.fatal("KEYSET ITERATION["+n+"] class["+n.getClass().getName()+"]");
      
       table.setRowKey(n);
       TransferObject to = (TransferObject)table.getRowData();
       }
       }
      
       public TreeModel getTree(){
       AppUtils.LOG.fatal("GET TREE............");
       return tree;
       }
      }
      
      


      Since we can not bind the tree component to the class (this is a conversation scoped bean), we are using the selectionListener.

      However, the listener is not getting called until *after* the commandButton lister.save action is called (that is the button that is pressed). Therefore, I don't have the information in the save method about what rows are selected.

      Thoughts on other approaches to try?

      Seam 1.2.p1
      MyFaces
      jboss 4.0.4

      Thanks,
      Chris....