Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
2.0.4
-
None
-
None
Description
Say we have an action, AddCustomer with one data element Customer customer;
AddCustomer-validation.xml contains a single visitor validator definition for customer.
Customer-validation.xml contains various validations including a visitor validator for Address address;
Address-validation.xml contains various validations including the following:
<field name="city">
<field-validator type="requiredstring" short-circuit="true">
<message>city is required</message>
<field-validator>
<field-validator type="fieldexpression" short-circuit="true">
<param name="expression">(some expression that will fail for an empty string</param>
<message>city is invalid</message>
</field-validator>
</field>
While testing a validation setup similar to this, I noticed that when nothing was entered for city on the web form, both error messages, ``city is required'', and ``city is invalid'', were being displayed.
The AppendingValidatorContext defined in VisitorFieldValidator overrides the default DelegatingValidatorContext getFullFieldName method to add the name of the visited object to the name. The name returned by getFullFieldName is then used by DefaultActionValidatorManager or AnnotationActionValidatorManager to determine if a field by this name already has errors and should be short-circuited.
However, it only adds the the name of the current visited object to the beginning, so for the example when validating city the name returned is just ``address.city'', but the field errors being added are being added with the name customer.address.city.
I fixed the behavior of the AppendingValidatorContext by changing it as follows:
private class AppendingValidatorContext extends DelegatingValidatorContext {
Object o;
String field;
String message;
String fullField;
public AppendingValidatorContext(ValidatorContext parent, Object object, String field, String message)
{ super(parent, makeTextProvider(object, parent), parent); // super(parent); fullField = parent.getFullFieldName(field); this.field = field; this.message = message; }/**
- Translates a simple field name into a full field name in Ognl syntax
*
- @param fieldName
- @return field name in OGNL syntax
*/
public String getFullFieldName(String fieldName)
{ return fullField + "." + fieldName; }public void addActionError(String anErrorMessage)
{ super.addFieldError(field, message + anErrorMessage); }public void addFieldError(String fieldName, String errorMessage)
{ super.addFieldError(field + "." + fieldName, message + errorMessage); }}
Attachments
Issue Links
- is related to
-
XW-618 invalid field names and broken short-circuit functionality when using nested visitor validators
- Resolved