It is very easy to collect the checked nodes on the server.
You could use a valueChangeListener. 

<t:selectBooleanCheckbox value="#{node.checked}"
    valueChangeListener="#{MyBean.mynode.nodeChanged}"
    title="#{node.identifier}"/>        
                    
Then you could add all selected nodes into a Set/List and remove all
deselected nodes from it.

public void nodeChanged (ValueChangeEvent ve) {
        HtmlSelectBooleanCheckbox sender = (HtmlSelectBooleanCheckbox)
ve.getComponent();
        if (sender.isSelected()) {
                //add selected node
                this.selectedNodes.add(sender.getTitle());
        }
        else{
                //remove not selected node
                this.selectedNodes.remove(sender.getTitle());
        }
}

-----Original Message-----
From: Philippe Lamote [mailto:[EMAIL PROTECTED] 
Sent: Dienstag, 23. Mai 2006 12:12
To: MyFaces Discussion
Subject: Tree2 & CheckedNode question

Hi,

I'm sory for this question, but there's not too much doc about this  
on site, so... here we go:

I want to make a tree2 with checkboxes that I only collect once  
together, and I could use some advice:

The examples I've seen, have the commandlink at every node, by  
consequence fire off the second one gets clicked.

What I want, is:
- a CLIENT side tree2 (for speed)
- with checkboxes on every leaf element
- multiple leafs can be checked simultaneously ("simultaneously"  
meaning before a new request fires off)
- under the tree a cmd button to ONLY THEN fire off an action.

The action should then perform an opeation on all the checked leafs.

I guess thsi is possible, but how to do this best?
If possible, I'd like a solution without javascript to collect the  
checked nodes, yet if no other way exits, that's fine too.
With js I thought of smth like: (if it works, "addToRequest(# 
{node.identifier});" ... should add the node ID to the request. So  
all checked nodes would be sent with the request wen the cmd button  
under the tree gets clicked.)

  <t:tree2 id="clientTree" value="#{calmgmtbean.treeModel}"  
var="node" varNodeToggler="t">
        <f:facet name="setsTree">
                <h:panelGroup>
                        <h:selectBooleanCheckbox onclick="addToRequest(#

{node.identifier});" />
                         <t:graphicImage
value="..pics/calMgmt/document.png" border="0"/>
                         <h:outputText value="#{node.description}"
styleClass="# 
{t.nodeSelected ? 'treeSetSelected':'treeSetUnselected'}"/>
                </h:panelGroup>
        </f:facet>
</t:tree2>      

If possible, I would like to get rid of "addToRequest(# 
{node.identifier});", of even better of the entire  
"h:selectBooleanCheckbox" and use checkedNode (smth Matthias  
Wessendorf provided us with for convenience - thank you Matthias! :-)

Yet in that case, how to collect all the ckecked nodes at the server  
side?
Is it necessary to walk over all the nodes and perform a isChecked  
check? (if so, does someone here has some tested code for this? Would  
be a ice addition to http://wiki.apache.org/myfaces/Tree2 as well.
I think this would also be a fine candidate for a build-in method, to  
ship with the ckeckNode tree. As with a checkednode tree, you have  
the great option to batch process all checked nodes at once,  
serverside, compared to all the servertrips per checked node you'd  
have without a checkednode tree. (this is what I love most about it,  
it's a great idea, yet now I guess every dev has to program the same  
method over and over again for tree-traversal)

Thanks in advance,
Phil





Reply via email to