myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Graeme Steyn" <>
Subject Validating Multiple Components in DataTable
Date Fri, 20 Jul 2007 10:56:16 GMT
I have a <tr:table> component that is displaying rows from an ArrayLIst
containing instances of class X.  I would like to introduce a validator
that checks that if information is entered for any property, then all
properties must be populated for that row.  ANy rows that have no data
entered or all data entered are thus valid. At present I have the
arrangement provided below, but I appear to be getting the instances of
X from the original collection, rather than the table components local
values.  Thus when the view is first displayed, I can enter data in row
1 cell 1 and press next to invoke a POST back and the validation.  Using
the debugger, I find that the first iteration through the loop returns
an instance of X, but without the posted back data (everything is null).
I do not appear to be getting at the local converted value.
Any help would be greatly appreciated.
Thank you,
I came across a related query located at  I am trying to avoid binding as the user
will be able to add and delete rows within my datatable, so I was hoping
to keep things flexible.
public class X {
private String prop1;
private String prop2;
private String prop3;
class BackingBean {
Collection <X> collection = new ArrayList <X> ();
<tr:message for="validateRows" />
        var="entry" >
            <tr:inputText value="#{entry.prop1} />
            <tr:inputText value="#{entry.prop2} />
<tr:inputHidden id="validateRows" value="dummy"
validator="#{bean.validateRows}" />

Will only catch the first invlaid instance in the table - the validation
message appears at the table level rather than per row.
    public void validateEntriesComplete(FacesContext facesContext,
            UIComponent uIComponent,
            Object object) throws ValidatorException {
        UIXCollection uixCollection = (UIXCollection) coreTable;
        int oldRowIndex = uixCollection.getRowIndex();
        for (int rowNum = 0, numRows = uixCollection.getRowCount();
rowNum < numRows; rowNum++) {    
            X instancex = (X) uixCollection.getRowData();
            if (!instancex.isAllPropertiesSet()
            && instancex.isAnyPropertySet()) {
                FacesMessage message = Messages.getMessage(
                        "IncompleteRecord", null);
                throw new ValidatorException(message);

View raw message