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

    Trinidad/TreeTable and how to determine selected rows

      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....

        • 1. Re: Trinidad/TreeTable and how to determine selected rows
          pmuir

          You can bind the tree table into an event scoped component and inject that into the conversation scoped component or use @In("#{uiComponent['idOfComponent'}) to inject it.

          • 2. Re: Trinidad/TreeTable and how to determine selected rows

            Pete - thanks for the info. That is exactly what I need and it works great!

            On a related topic, do you think it would be possible to create something similar to @DataModel/@DataModelSelection for TreeModel?

            I started to look at the DataModelBinding classes last night; but didn't have time to get very far. If you had thoughts about how this could be accomplished they would be appreciated since I really don't like binding directly to the UI component.

            Chris...

            • 3. Re: Trinidad/TreeTable and how to determine selected rows
              pmuir

              It should be possible, but its not on the roadmap for Seam. It would be better to get the listener style approach working properly.

              • 4. Re: Trinidad/TreeTable and how to determine selected rows


                When watching my debug statements the listener method was being called after the action method. Not being a complete expert on the JSF lifecycle is this a Seam issue or a JSF issue. Where would you recommend I look first?

                I would have thought the listener method being called after the action method was a JSF issue, which makes it even harder to fix.

                I'm using Seam 1.2.p1 and myfaces 1.x.

                Thoughts,
                Chris.....