Thank you for your good explanation. Nevertheless I'll prefer to do it the
Java way 'cos the validation is more complicated than just do some tests for
required string properties.
  Dirk Forchel


Greg Lindholm wrote:
> 
> I see what you are asking for, but sorry I'm sure it doesn't exist, there
> is no annotation combining logic, each validation annotation has to
> stand-on-its-own.
> 
> So to do what you are asking, you couldn't use the
> @RequiredStringValidator, you would need to use a Expression Validator and
> combine the logic.  
> To take your example, if "privatePerson" is true you want "name",
> "number1", and "number2" to be required.
> 
> You would need to write three expression validators:
> 
> @ExpressionValidator(expression = " !(privatePerson &&
> name.trim().isEmpty())", ...) 
> @ExpressionValidator(expression = " !(privatePerson &&
> number1.trim().isEmpty())", ...) 
> @ExpressionValidator(expression = " !(privatePerson &&
> number2.trim().isEmpty())", ...) 
> 
> You can then use the @Validations to apply a list of expression
> validations.
> 
> Again, given these limitation, at some point it easier to do it in Java.
> 
> 
> Dirk Forchel wrote:
>> 
>> Thank you for your posting. I already know how to use the
>> @FieldExpressionValidator and annotations at property level (on setter
>> methods) or how to use the validators with annotations at method level
>> (@Validations for an execute() method). But I did not get it work with
>> the @ExpressionValidator and conditional clauses. So let's say:
>> 
>> privatePerson is a boolean property. If privatePerson==true do some
>> validation and if privatePerson==false do some different validation. For
>> instance, if privatePerson==true I wanna use required string validators
>> for the field properties "name", "number1" and "number2". But if
>> privatePerson==false I wanna use only the field validator for "number1".
>> But I miss the conditional part.
>> 
>> @Validations(
>>    requiredStrings = {
>>      @RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName =
>> "name", message = "You must enter a value for name."),
>>      @RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName =
>> "number1", message = "You must enter a value for number1."),
>>      @RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName =
>> "number2", message = "You must enter a value for number2.")
>>    },
>>    expressions = {
>>       @ExpressionValidator(expression = "privatePerson", message="",
>> key="")
>>    }
>> )
>> public String execute() throws Exception {
>>         return SUCCESS;
>> }
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Conditional-Annotation-based-Validation-tp21328921p21377468.html
Sent from the Struts - User mailing list archive at Nabble.com.


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

Reply via email to