aspose file tools*
The moose likes JSF and the fly likes How do you implement Tomahawk tree control with a CheckBox? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How do you implement Tomahawk tree control with a CheckBox?" Watch "How do you implement Tomahawk tree control with a CheckBox?" New topic
Author

How do you implement Tomahawk tree control with a CheckBox?

Lisa Dony
Greenhorn

Joined: Apr 14, 2010
Posts: 2
I have been trying to implement the Tomahawk tree control with the column tag using a CheckBox control within the column, I am not able to determine what checkbox was checked for what node in the tree. Here is my original jsf tree code:

<t:tree
value="#{MyController.treeModel}"
var="node" expandRoot="true"
styleClass="treeTable" >

<t:treeColumn>
<f:facet name="header">
<hutputText value="ANumber" />
</f:facet>
<hutputText value="#{node.aNumber}" />
</t:treeColumn>

<h:column id="column1">
<f:facet name="header">
<hutputText value="Select"></hutputText>
</f:facet>
<h:selectBooleanCheckbox id="relation" value="#{node.selected}" >
</h:selectBooleanCheckbox>
</h:column>
</t:tree>


I loaded several nodes into the TreeModel object. Once the screen was displayed with all the nodes, I thought, all should work fine without having to do anything. That is, that if I selected a checkbox that the node I selected would be selected for the specific node selected in the tree (ie. the node in the TreeModel object would have it's "selected" attribute to be true). However, this doesn't seem to be the case and all the "selected" attributes for all nodes are still false. It looks like you can't change data within a TreeModel object once it is rendered on the screen.

So, I thought I would try to programatically try to get the node selected and perhaps set it in the TreeModel upon checking the checkbox. To do this, I added the valueChangeListener MyController.doNodeSelected and an attribute "aNumber" so I could tell what node was checked.

<t:tree
value="#{MyController.treeModel}"
var="node" expandRoot="true"
styleClass="treeTable" >

<t:treeColumn>
<f:facet name="header">
<hutputText value="ANumber" />
</f:facet>
<hutputText value="#{node.aNumber}" />
</t:treeColumn>

<h:column id="column1">
<f:facet name="header">
<hutputText value="Select"></hutputText>
</f:facet>
<h:selectBooleanCheckbox id="relation" value="#{node.selected}"
valueChangeListener="#{MyController.doNodeSelected}" onchange="submit()" >
<f:attribute name="aNumber" value="#{node.aNumber}" />
</h:selectBooleanCheckbox>
</h:column>
</t:tree>

When I click on the checkbox the valueChangeListener "MyController.doNodeSelected" is called. I then tried to get at the attribute "aNumber" value using the following code:

public void doAccountNodeSelected(ValueChangeEvent event) {
String aNumber = (String) event.getComponent().getAttributes().get("aNumber");
}

The value I'm getting in aNumber does not represent the checkbox of the node I clicked. If I change the <f:attribute name="aNumber" value="5678" /> then I get "5678".

So, it looks like I'm stumped on how to get a checkbox column to work in the tree control. Does anyone have any examples of this? I've been searching the net, and can't find anything. I'd also like to consider using the "treeColumn" code, but I can't find the sample Bean code that goes with the sample jsf found in: http://www.developersbook.com/jsf/myfaces/tomahawk-tag-reference/tomahawk-treeCheckbox.php .




Lisa Dony
Greenhorn

Joined: Apr 14, 2010
Posts: 2
I'm using tomahawk12-1.1.9. My TreeModel object for use in my tree control has several objects in it where the object has an attribute "aNumber". I'm finding that both the f:param and f:attribute are not returning the correct "aNumber" when used with either the commandLink or selectBooleanCheckBox control. I've tried both the f:param and f:attribute on both the commandLink and selectBooleanCheckBox control, but when I select the commandLink "Edit" link or select a checkbox, I am always getting the LAST "aNumber" on the page. Is f:param and f:attribute expected to work within the tomahawk tree control? Here is my jsf code with both the commandLink and selectBooleanCheckBox. You can see I've changed the column controls to treeColumn, but this still doesn't seem to play a role in getting the right value from f:param or f:attribute. Is there some trick to getting the f:param or f:attribute to work or is this a bug in the tomahawk tree control?


<t:tree
value="#{myController.treeModel}"
var="node" expandRoot="true" >
<t:treeColumn>
<f:facet name="header">
<hutputText value="A Number" />
</f:facet>
<hutputText value="#{node.aNumber}" />
</t:treeColumn>
<t:treeColumn id="column5">
<f:facet name="header">
<hutputText value="Edit"></hutputText>
</f:facet>
<h:commandLink action="MyEdit"
actionListener="#{myController.doEdit}"
rendered="#{node.visible}" value="Edit">
<f:param name="aNumber" value="#{node.aNumber}" />
</h:commandLink>
</t:treeColumn>
<t:treeColumn id="column6">
<f:facet name="header">
<hutputText value="Select"></hutputText>
</f:facet>
<t:selectBooleanCheckbox id="relation" value="#{node.selected}"
rendered="#{node.visible}"
valueChangeListener="#{myController.doNodeSelected}"
onchange="submit()" title="#{node.aNumber}">
<f:attribute name="aNumber" value="#{node.aNumber}" />
</t:selectBooleanCheckbox>
</t:treeColumn>
</t:tree>




 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do you implement Tomahawk tree control with a CheckBox?