wood burning stoves 2.0*
The moose likes JSF and the fly likes Tomahawk (myfaces) tree table not able to identify the checkbox component inside valuechangelistener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Tomahawk (myfaces) tree table not able to identify the checkbox component inside valuechangelistener" Watch "Tomahawk (myfaces) tree table not able to identify the checkbox component inside valuechangelistener" New topic
Author

Tomahawk (myfaces) tree table not able to identify the checkbox component inside valuechangelistener

Umesh Se
Greenhorn

Joined: Aug 26, 2009
Posts: 1
Hi All,

I'm trying to use tomahawk(myfaces) tree table component to render a tree column of items along with checkboxes in other columns. Note that all the other columns except tree column are generated dynamically inside backing bean and checkboxes too added to the column dynamically.
All works fine until it comes to the valuechangelistener.Inside valuechangelistener if try to fetch the component id from the event, it doesn't return the correct id and instead always return the id that corresponds to the last node of tree.

Has anyone successfully used tree table to display input components? or any workaround my problem would be much appreciated.

The code where I'm adding my dynamic columns as well as checkboxes is as below.

for (int i = 0; i < roleNames.size(); i++) {

HtmlSimpleColumn column = new HtmlSimpleColumn();
htmlTree.getChildren().add(column);

// Create header
HtmlOutputText header = new HtmlOutputText();
header.setValue(roleNames.get(i));
column.setHeader(header);


ValueExpression valueExpression = FacesContext
.getCurrentInstance().getApplication()
.getExpressionFactory()
.createValueExpression(
FacesContext.getCurrentInstance().getELContext(),
"#{treeItem.name}",
Object.class);


// Create check box
HtmlSelectBooleanCheckbox checkbox = new HtmlSelectBooleanCheckbox();

// add the hidden input elements
HtmlInputHidden input = new HtmlInputHidden();
HtmlInputHidden input1 = new HtmlInputHidden();


// Bind changeRolePresent method in to listen to the
// role permission change
checkbox.setImmediate(true);

Class<?>[] parms = new Class[] { ValueChangeEvent.class };
System.out.println("Adding value change listener to permission grid");
MethodExpression valueChangeListener = FacesContext
.getCurrentInstance().getApplication()
.getExpressionFactory().createMethodExpression(
FacesContext.getCurrentInstance()
.getELContext(),
"#{customTreeBean.changeRolePermission}",
String.class, parms);
checkbox
.addValueChangeListener(new MethodExpressionValueChangeListener(
valueChangeListener));

input.setValueExpression("value", valueExpression);
input1.setValue(roleNames.get(i));


valueExpression = app
.getExpressionFactory()
.createValueExpression(
FacesContext.getCurrentInstance().getELContext(),
"#{treeItem.roleDetailsList["i"].selectedRole}",
Object.class);

checkbox.setValueExpression("value", valueExpression);

//checkbox.setOnclick("selectAll(this)");
checkbox.getChildren().add(input);
checkbox.getChildren().add(input1);
column.getChildren().add(checkbox);
}

In above code there will be four columns added dynamically and for each column a checkbox component is being added here. Rest JSF takes care to create checkboxes for each row of tree. But one thing that I noticed while viewing source that JSF is creating duplicate names for checkboxes in a batch of four (So for say if I had 3 rows, every row of checkboxes had same set of four ID's assigned, like ID1, ID2, ID3, ID4)

Thanks,
Umesh
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Tomahawk (myfaces) tree table not able to identify the checkbox component inside valuechangelistener