@Inject private FieldValidatorSource source; @InjectComponent private Field yourField;
public FieldValidator getDynamicConstraints() { return source.createValidators(yourField, "required", null); } Note that this is how we generally use Tapestry Services by injecting them. Have a look at the API, it is pretty detailed on how to use methods on services. Also, keep in mind that there are two types of services : public (for tapestry users) and internal (for tapestry developers) So if you're looking at something, have a first look into the 'org.apache.tapestry5.services' package, you should find what you need ;) Regards, Christophe Cordenier. 2010/3/18 Jagadesh Paladugula <jagadeshpaladug...@gmail.com> > Hi Christophe, > > Could you please give me a sample implementation. > > Regards, > Jagadesh > > On Thu, Mar 18, 2010 at 12:39 PM, Christophe Cordenier < > christophe.corden...@gmail.com> wrote: > > > Hi > > > > Try with fielvalidtorsource service to build your conditional > constraints. > > > > Regards > > Christophe cordenier > > > > Le 18 mars 2010 à 06:59, Jagadesh Paladugula < > jagadeshpaladug...@gmail.com> > > a écrit : > > > > > > Hi Everyone, > >> > >> I have a form which is getting generated dynamically based on some > values > >> in > >> database. I want to add validation for a text box based on some > condition. > >> > >> I tried doing some thing like this > >> > >> <t:textfield t:validate="*${validator}*"></t:textfield> > >> > >> and added the below method in respective java file > >> > >> public String getValidator(){ > >> if(test for validation condition){ > >> return "required"; > >> }else{ > >> return ""; > >> } > >> } > >> > >> I am getting some exception saying *"Could not find a coercion from type > >> java.lang.String to type org.apache.tapestry5.FieldValidator."* > >> > >> From the exception, I understood that it is expecting FieldValidator, > but > >> I > >> am not getting how to initalize a *"required" FieldValidator* and return > >> it. > >> > >> I have one more fix (which I didn't like) > >> <t:if test="test for validation"> > >> <t:textfield t:validate="*${validator}*"></t:textfield> > >> <t:parameter name="else"> > >> <t:textfield></t:textfield> > >> </t:parameter> > >> </t:if> > >> > >> > >> Please Let me know, if there is a way to initalize a FieldValidator. > >> > >> -- > >> Thanks & Regards > >> Jagadesh > >> > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > > For additional commands, e-mail: users-h...@tapestry.apache.org > > > > > > > -- > Regards > Jagadesh > -- Regards, Christophe Cordenier. Developer of wooki @wookicentral.com