Here is another way:

<f:facet name="somenode">
 <t:panelGroup>
   <t:selectBooleanCheckbox
     valueChangeListener="#{bean.treeCheckChanged}">
     <f:attribute name="nodeId" value="#{node.identifier}" />
   </t:selectBooleanCheckbox>
   ...

Java:
 public void treeCheckChanged(ValueChangeEvent evt)
 {
   UIComponent comp = evt.getComponent();
   String nodeId = (String)comp.getAttributes().get("nodeId");

   Boolean oldValue = (Boolean)evt.getOldValue();
   Boolean newValue = (Boolean)evt.getOldValue();
   ...
 }

The one thing weird about this is that it occurs during the process
validation and not the update model phase (I always wonder why the
value change isn't in the update model phase), so it isn't fully
acceptable to be changing the bean's properties at this time, but what
other possibility is there?

-Andrew


On 5/23/06, Michael Heinen <[EMAIL PROTECTED]> wrote:
Here is some more code of my jsp for illustration:

<t:tree2 id="catTree" value="#{MyBean.mynode.treeData}"
        var="node"
        varNodeToggler="t"
        clientSideToggle="false"
        showRootNode="true">
  ...
        <f:facet name="category">
            <h:panelGroup>
               <t:selectBooleanCheckbox value="#{node.checked}"

valueChangeListener="#{MyBean.mynode.nodeChanged}"
                 title="#{node.identifier}"/>

<h:outputText value="#{node.description}" styleClass="nodeFolder"/>
<h:outputText value=" (#{node.childCount})" styleClass="childCount"
rendered="#{!empty node.children}"/>

            </h:panelGroup>
        </f:facet>
        ...
</t:tree2>

-----Original Message-----
From: Michael Heinen [mailto:[EMAIL PROTECTED]
Sent: Dienstag, 23. Mai 2006 17:50
To: MyFaces Discussion
Subject: RE: Tree2 & CheckedNode question

Phil,

I think the performance could depends on your specific scenario (size of
tree, number of changed nodes and their relation). My model contains
very large server side trees so checking the whole tree was not an
alternative for me.

You need the <t:selectBooleanCheckbox> in order to display the checkbox
for the corresponding node. The valueChangeListener must be defined for
this tag. You can't define it elsewhere because it should be fired when
the checkbox status has been changed.

The sender of the valueChangeEvent is not a TreeNodeChecked but a
HtmlSelectBooleanCheckbox. HtmlSelectBooleanCheckbox has not
getIdentifier() method. Attribute title of HtmlSelectBooleanCheckbox
contains the identifier of the node in my sample.  See below:
title="#{node.identifier}"

I also don't know <t:treeSelectionListener>.

Michael

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

Ah, so I did miss smth! (my bad)
This is very interesting.
I'll try that out.

Do you think this is a more efficient (meaning faster) approach than
sending the whole tree back, and do a tree traversal in one action
method to add selected nodes to an List? (= optimization question;
one big action traversal method vs. serveral smaller action listener
methods) Have you experimented with this?

Last question: if I 'd use Matthias's CheckedNode Tree, can I then
leave the <t:selectBooleanCheckbox> out of the tree or should I leave
it in? (as having to leave it out raises the problem of where to put
the valueChangeListener; neither facet not panelGrid accept this
attribute)

So, for TreeNodeChecked: (btw I also noticed you used getTitle()
instead of getIdentifier(), why is that?)
--> would this be the proper way for handling:

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


Btw does anyone know what the "<t:treeSelectionListener>" element
stands for? (passed by with autocompletion, yet no doc is available &
I'd also expect an actionListener to go with a "Listener" yet this is
not the case)

Bye ( & thx Michael!)
Phil


On 23 May 2006, at 14:16, Michael Heinen wrote:

There is only one request.
The valueChangeListener listener is called after you submitted your
page. You can select/deselect as many nodes as you want in a client side
tree without generating a server request. The valueChangeListener is
called after you submitted the form. It is then called for each changed
node.

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

This seems worse then a resquest per checked node: now you have a
server round trip per time a user "clicks" on +/-
The best solution is (as in my question) one where there is ONLY one
request, at the end.
Then only the nodes the user selected in the end (after his doubts -
think proces of checking/unchecking) are taking into account.
(or am I missing smth?)
Phil


On 23 May 2006, at 12:39, Michael Heinen wrote:

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