How do you define multiple validators though? ----- Original Message ----- From: "Scott F. Walter" <[EMAIL PROTECTED]> To: "Tapestry users" <[email protected]> Sent: Saturday, July 02, 2005 11:46 AM Subject: Re: Tapestry 4 Validation Question
> kranga wrote: > > >I'm interested in the answer to this too - can someone shed light on this? > > > >----- Original Message ----- > >From: "Scott F. Walter" <[EMAIL PROTECTED]> > >To: <[email protected]> > >Sent: Friday, July 01, 2005 3:51 PM > >Subject: Tapestry 4 Validation Question > > > > > > > > > >>So the format for the new validator syntax is : > >> > >>validator:/name/[,/property/[=/value/]]* > >> > >>My questions are: > >>1. If I create my own custom validator what do I specify for "name", is > >> > >> > >it the full qualified class path or do I need to some how register "name" > >with a full qualified class path? > > > > > >>2. Using the format above, how can I have multiple validators? > >> > >>thanks, scott. > >> > >> > >>-- > >> > >>Scott F. Walter Scott F. Walter > >>Principal Consultant > >>Vivare, Inc. > >> > >>E: [EMAIL PROTECTED] > >>E: [EMAIL PROTECTED] > >>Visit scottwalter.com <http://scottwalter.com> --Point. Click. Explore! > >> > >> > >> > >> > >>--------------------------------------------------------------------- > >>To unsubscribe, e-mail: [EMAIL PROTECTED] > >>For additional commands, e-mail: [EMAIL PROTECTED] > >> > >> > >> > >> > > > > > > > >--------------------------------------------------------------------- > >To unsubscribe, e-mail: [EMAIL PROTECTED] > >For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > I figured it out! To create and user a custom validator, follow these > steps: > > 1. Create a class that extends > org.apache.tapestry.form.validator.BaseValidator > 2. If you want parameters to be passed into your validator, create a > constructor that takes a String > 3. Override the validate method() > 4. Provide a contribution to tapestry.form.validator.Validators in > hivemodule.xml (stored in your WEB-INF directory) > > Below are my custom validator and my hivemodule.xml file > > import org.apache.tapestry.form.IFormComponent; > import org.apache.tapestry.form.ValidationMessages; > import org.apache.tapestry.form.validator.BaseValidator; > import org.apache.tapestry.valid.ValidatorException; > > /** > * > * @author scott > */ > public class MyNameValidator extends BaseValidator { > > /** Creates a new instance of MyNameValidator */ > public MyNameValidator() { > } > > public void validate(IFormComponent field, > ValidationMessages messages, > java.lang.Object object) > throws ValidatorException { > > if(object!=null && !object.toString().equalsIgnoreCase("scott")) { > throw new > ValidatorException(messages.formatValidationMessage(null, > "invalid-format", null)); > } > > } > } > > <?xml version="1.0"?> > > <module id="tapestry4sandbox" version="1.0.0" > package="com.scottwalter.sandbox.tapestry4"> > <contribution configuration-id="tapestry.form.validator.Validators"> > <validator name="myname" configurable="false" > class="com.scottwalter.sandbox.tapestry4.MyNameValidator"/> > </contribution> > </module> > > Then inside my specification file, I have a component like the one > below: (Notice "myname" maps into the hivemodule,xml) > > <component id="firstNameField" type="TextField"> > <binding name="value" value="ognl:person.firstName"/> > <binding name="validators" value="required,minLength=3,myname"/> > <binding name="displayName" value="First Name"/> > </component> > > > The only problem I am having is to have localized error messages > returned. I have defined a global message space file, and I have a key > in the properties file, but when I try to reference in my custom > validator like this: > > formatValidationMessage(null, "namenotscott", null) I get this > exception at runtime: > > java.util.MissingResourceException Can't find resource for bundle > java.util.PropertyResourceBundle, key namenotscsott > > For the "messageKey" parameter, I can only get values from > ValidationStrings.properties (which is located in the tapestry jar file). > > So my question is when formatting validation messages how do I specify > the location of the resource bundle to use???? > > > -- > > Scott F. Walter Scott F. Walter > Principal Consultant > Vivare, Inc. > > E: [EMAIL PROTECTED] > E: [EMAIL PROTECTED] > Visit scottwalter.com <http://scottwalter.com> --Point. Click. Explore! > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
