Hey,
I tried solving it the following way using the FieldValidatorSource service:
<t:textfield t:id="someField" t:value="someValue"
t:validate="prop:someFieldValidate" />
public FieldValidator<Object> getSomeFieldValidate() {
StringBuilder validate = new StringBuilder()
.append("required")
.append(",")
.append("regexp="+SOME_REGEXP);
return fieldValidatorSource.createValidators(someField,
validate.toString());
}
But now I have a problem when SOME_REGEXP contains a space character it
throws following error:
java.lang.RuntimeException
*Unexpected character ']' at position 26 of input string:
required,regexp=^[A-ΓΏ'\- ]*$*
org.apache.tapestry5.internal.services.FieldValidatorSourceImpl
parseError() FieldValidatorSourceImpl.java 422
org.apache.tapestry5.internal.services.FieldValidatorSourceImpl parse()
FieldValidatorSourceImpl.java 381
org.apache.tapestry5.internal.services.FieldValidatorSourceImpl
toValidatorSpecifications() FieldValidatorSourceImpl.java 199
org.apache.tapestry5.internal.services.FieldValidatorSourceImpl
createValidators() FieldValidatorSourceImpl.java 182
...
I used this same regexp value in the @Validate annotation before without
problems, but with my method above it gives the above parsing error.
Anyone know how I can solve the above problem?
Nathan
On 15/09/16 16:20, Nathan Quirynen wrote:
> Hi,
>
> I want to use the @Validate annotation, but I cannot put it at the
> value properties, because these properties are part of a DTO object
> that is part of a library.
> In the documentation
> (
http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/beaneditor/Validate.html)
> I found the following: " May be placed on any getter or setter method,
> or on the matching field".
>
> So I thought I could do the following:
>
> @Validate("regexp="+SOME_REGEXP)
> @InjectComponent
> private Field someField;
>
> But this does not seem to work?
>
> Is there any other way to add validators to a field programatically
> when you have no access to the property declarations?
> I could do all validation myself in the onValidate event, but this
> does not seem optimal.
>
> Nathan
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
[hidden email]
> For additional commands, e-mail:
[hidden email]
>
>