import org.apache.tapestry5.Field;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.ValidationException;
import org.apache.tapestry5.ioc.MessageFormatter;
import org.apache.tapestry5.services.FormSupport;
/* A vaidator that enforces that a number is greater than some minimum
integer value. */
public class MinDouble extends AbstractValidator<Double, Number>
{
public MinDouble()
{
super(Double.class, Number.class, "min-double");
}
public void validate(Field field, Double constraintValue,
MessageFormatter formatter, Number value)
throws ValidationException
{
if (value.doubleValue() < constraintValue)
throw new ValidationException(buildMessage(formatter,
field, constraintValue));
}
private String buildMessage(MessageFormatter formatter, Field
field, Double constraintValue)
{
return formatter.format(constraintValue, field.getLabel());
}
public void render(Field field, Double constraintValue,
MessageFormatter formatter, MarkupWriter writer,
FormSupport formSupport)
{
//This is only required if you want to have a client side
validation too.
//In that case you have to add a method in Tapestry.Validation
formSupport.addValidation(field, "min",
buildMessage(formatter, field, constraintValue), constraintValue);
}
}
and then contribute it to FieldValidatorSource
public static void
contributeFieldValidatorSource(MappedConfiguration<String, Validator>
configuration)
{
configuration.add("min-double", new MinDouble());
}
also add the message.
On Wed, Aug 17, 2011 at 11:26 PM, leothelion <[email protected]> wrote:
> You mean hack into T5 code and create the min-double validator?
> Sorry, I am not sure what exactly I should do.
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Question-about-FieldValidator-tp4706033p4709223.html
> Sent from the Tapestry - Dev mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
--
Regards
Taha Hafeez Siddiqi (tawus)
http://tawus.wordpress.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]