Posted By:
Frank_Z
Posted On:
Thursday, April 3, 2008 04:04 PM
I would like to mark fields (list of fields in a DataTable that correspond to an ArrayList) having validation-messages with a certain error-style (red background). I wrote a PhaseListener that works fine for standard form-fields. I am taking the fieldId from a message to find the component in the jsf-view tree and assign that styleCss to it. But unfortunately that does not work with a list in a DataTable. Here's, what i'm trying to do: I have a list of persons, i am displaying in an editable form with a dataTable. As aforementioned i would like to mark the fields with validation errors in red. The input filed-ids are rendered with index like name[n] and the messages field-ids also have this pattern
More>>
I would like to mark fields (list of fields in a DataTable that correspond to an ArrayList) having validation-messages with a certain error-style (red background). I wrote a PhaseListener that works fine for standard form-fields. I am taking the fieldId from a message to find the component in the jsf-view tree and assign that styleCss to it. But unfortunately that does not work with a list in a DataTable.
Here's, what i'm trying to do: I have a list of persons, i am displaying in an editable form with a dataTable. As aforementioned i would like to mark the fields with validation errors in red.
The input filed-ids are rendered with index like
name[n]
and the messages field-ids also have this pattern. But in the jsf view only a component with the id "name" can be found. When i assign the error-style to it, all the input fields in the list are marked in red. Any suggestions?
Here is a part of my PhaseListener. It shows, how i search for the component, that has an error message.
...
UIComponent c = findComponent(root, messageId);
if (c != null) {
if (c instanceof HtmlInputText) {
HtmlInputText input = (HtmlInputText) c;
input.setStyleClass(CSS_ERROR_INPUT);
...
private UIComponent findComponent(UIComponent base, String id) {
// Search through our facets and children
UIComponent result = null;
for (Iterator
<?> i = base.getFacetsAndChildren(); i.hasNext();) {
UIComponent kid = (UIComponent) i.next();
if (id.equals(kid.getId())) {
result = kid;
break;
}
result = findComponent(kid, id);
if (result != null) {
break;
}
}
return (result);
}