Hello,

Because I had a big struggle for two days with the tree2 component and
selectbooleancheckboxen, I like to share my information with other people.

What I wanted was a server-side tree2 with selectbooleancheckboxen. If a
checkbox is checked, all direct childs under this node should also be
selected. I was able to update the ''checked'' values in the nodes in the
tree, but to get the checkboxes updated in the browser was a big problem for
me.

Somehow you want to access the HtmlSelectBooleanCheckbox component that
belongs to the node. In JSF it's possible to do a server side walk through
the components of your website.
I was able to find the tree2 component but not any of the
selectbooleancheckboxen in this tree.

If you choose a valueChangeListener you easily can access the check box and
uncheck the checkbox by using the code:

public void function_name_listener (ValueChangeEvent event) {
   HtmlSelectBooleanCheckbox sender =
(HtmlSelectBooleanCheckbox)event.getComponent();
   sender.setSelected(false);
}

But this only works for one checkbox, the one you checked or unchecked.

Finally I found a piece of useful code in the function encodeCurrentNode()
in org.apache.myfaces.custom.tree2.HtmlTreeRenderer.java.

Let's take a example tree structure and facet:

root
    one
        two
             three

So if a checkbox from  "one" is selected all "two" nodes under this "one"
will also be selected.


 <f:facet name="two">
   <h:panelGroup>
       <t:selectBooleanCheckbox id="man"
onchange="common_timeoutSubmitForm(this.form, '');"
             title="#{node.nodePath}" value="#{node.checked}" 
             valueChangeListener=" {treeBacking.checkboxChangeManager}"/>

       <h:outputText value="#{node.description}"/>
  </h:panelGroup>
</f:facet>

If the name of your tree2 component is "serverTree" and it placed in form
"form1" you can 
create a HtmlTree with:
        
       HtmlTree tree =
(HtmlTree)FacesContext.getCurrentInstance().getViewRoot().findComponent("form2:serverTree");
 

        //set the node from which you want to obtain the
HtmlSelectBooleanCheckbox component   
        tree.setNodeId("0:0:0");          TreeNode node = tree.getNode();
      
        // get the panelGroup component of this node
        UIComponent nodeTypeFacet = tree.getFacet(node.getType());
       
        // get the HtmlSelectBooleanCheckbox from child one of
"nodeTypeFacet"
        HtmlSelectBooleanCheckbox ui =
(HtmlSelectBooleanCheckbox)nodeTypeFacet.getChildren().get(0);
        ui.setSelected(true);

And in your browser the checkbox has been updated.

Does anyone know a way to get this down by built in function in tree2?

Regards,
Robert
-- 
View this message in context: 
http://www.nabble.com/Tree2-selectbooleancheckboxen--hint-tf3968749.html#a11265216
Sent from the MyFaces - Users mailing list archive at Nabble.com.

Reply via email to