I've made some progress on this on my own.  I needed to write my own version
of VisitorFieldValidator to make it work however.  

Once that was done, the model was being validated but all the error messages
were being assigned to the wrong field names.  The reason for this is that
the field names on my form are governed by the format defined in the Type
Conversion wiki entry: All the field names are defined as
collectionName(unique_id).propertyName where unique_id is the id defined by
the KeyProperties_ property entry in my model's conversion properties file.    

The VisitorFieldValidator uses the Collection index when constructing the
field name used to associate an error with a field:

 for (int i = 0; i < array.length; i++) {
            Object o = array[i];
            validateObject(fieldName + "[" + i + "]", o, visitorContext);
        }

So none of the errors get assigned back to the correct field name and then
can't be displayed properly.  

Getting the error messages associated with the right field name was a bit of
a trick however and I don't particularly like my implementation since it
seems fragile to me but I can't currently see a way around it.  

For my approach to work I needed to obtain o's unique Id and and assign it
in place of the value i in the code snippet above (i also needed to change
the square-brackets to parentheses).  I know that in all my use cases o is
going to have a getId method so I just hard-coded that.  Ideally, I'd like
to be able to use something in the xwork or OGNL APIs to determine the
KeyParameter from the conversion.properties file so that my code is more
dynamic but it seems pretty clear that all that information is tightly
encapsulated and out of reach.  Is there a sanctioned way for getting at the
KeyParameter information based on existing APIs?


-- 
View this message in context: 
http://www.nabble.com/-S2--Indexed-properties%2C-Type-Conversion-and-Validation-tp14654165p14676430.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to