AFAIK the expression validator is available via annotations. You can also use a custom validator but I find it a little clumsy with annotations.

Personally, as soon as validation gets even remotely complicated I fall back to using Java-based validation--I just think it's easier to maintain and much more clear.

I'll sometimes use a combination of both Java-based and either XML or annotations if it makes sense to.

On a side note, IIRC the "trim" attribute/parameter only applies the trim during validation--not on the value set on the action property.

Dave

Dirk Forchel wrote:
I have two radio buttons for a form property named "privatePerson" with two
possible values ('true' and 'false') which toogles the view of my input form
with three different input fields (number1, number2, name).
If the user choose "private" the number1, number2 and name input fields are
shown, if the user choose "non-private" only the number1 input field is
shown.
For the first choise I would use annotation based validation like

@Validations(
   requiredStrings = {...@requiredstringvalidator(type = ValidatorType.SIMPLE,
fieldName = "name", message = "You must enter a name.")},
   stringLengthFields = {...@stringlengthfieldvalidator(type =
ValidatorType.SIMPLE, trim = true, minLength="6", maxLength = "6", fieldName
= "number1", message = "The first part of the number must be 6 digits
long."), @StringLengthFieldValidator(type = ValidatorType.SIMPLE, trim =
true, minLength="4", maxLength = "4", fieldName = "number2", message = "The
second part of the number must be 4 digits long."),
} )
public String execute() throws Exception {
...
}

If the user selects "non-private" only the following validator should be
used.

@Validations(
    stringLengthFields = {...@stringlengthfieldvalidator(type =
ValidatorType.SIMPLE, trim = true, minLength="8", maxLength = "8", fieldName
= "number1", message = "The first part of the number must be 8 digits
long."),
} )
public String execute() throws Exception {
...
}


How can I accomplish this conditional annotation based validation?



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to