I want to set the style attribute of a com.inmethod.grid.column.PropertyColumn
within a com.inmethod.grid.TreeGrid
. The creation of the column is done as follows:
private PropertyColumn<DefaultTreeModel, DefaultMutableTreeNode, ConfigParamTreeNode> createCurrentValueColumn() {
PropertyColumn<DefaultTreeModel, DefaultMutableTreeNode, ConfigParamTreeNode> col = new PropertyColumn<DefaultTreeModel, DefaultMutableTreeNode, ConfigParamTreeNode>(
new Model<String>("Value"), "userObject.currentValue") {
private static final long serialVersionUID = 3525654933636874042L;
@SuppressWarnings("rawtypes")
@Override
public boolean cellClicked(IModel rowModel) {
ConfigParamTreeNodeModel treeNodeModel = (ConfigParamTreeNodeModel) (((DefaultMutableTreeNode) rowModel
.getObject()).getUserObject());
treeNodeModel.getNodeLabel();
AjaxRequestTarget target = AjaxRequestTarget.get();
confirm.open(target);
}
return true;
}
};
col.setResizable(true);
return col;
}
Which displays a popup dialog when the user clicks the cell.
After the dialog is dismissed, I want to do some validation on the value, and indicate any error on the cell. So my idea was to set a red border around it. But my problem is, how do I get the <div>
element associated with the cell, to set the style attribute on??
This can be done on a PropertyTreeColumn
because it provides a newNodeComponent
, in which you can access the Component object to set the style.
But how to do this on a PropertyColumn
?
Or if someone can recommend a way of doing validation on a TreeGrid, and how to indicate errors on an individual cell basis I would be very interested in your ideas.
Thanks.
You can try to override the PropertyColumn method getCellCssClass(), something like that:
PropertyColumn column = new PropertyColumn( columnId,new Model<String>( columnName ),
somePropertyExpression,
sortProperty ) {
@SuppressWarnings("rawtypes")
@Override
public String getCellCssClass( IModel rowModel,
int rowNum ) {
if( getId().equals( "testid" ) ) {
return "testCell";
} else if( getId().equals( "blablaId" ) ) {
return "blablaCell";
} else {
return null;
}
}
};