Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Umesh Se
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic