You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jagadesh Paladugula <ja...@gmail.com> on 2010/03/18 06:59:48 UTC
Validation based on condition
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
Re: Validation based on condition
Posted by Jagadesh Paladugula <ja...@gmail.com>.
Thanks Christophe. Its working :)
One more doubt, When I don't want to add validation, I am returning null, in
this case page is not getting rendered.
Should I need to create a new validator "Optional", make this as default
validator;
Regards,
Jagadesh
On Thu, Mar 18, 2010 at 1:01 PM, Christophe Cordenier <
christophe.cordenier@gmail.com> wrote:
> @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 <ja...@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.cordenier@gmail.com> wrote:
> >
> > > Hi
> > >
> > > Try with fielvalidtorsource service to build your conditional
> > constraints.
> > >
> > > Regards
> > > Christophe cordenier
> > >
> > > Le 18 mars 2010 à 06:59, Jagadesh Paladugula <
> > jagadeshpaladugula@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-unsubscribe@tapestry.apache.org
> > > For additional commands, e-mail: users-help@tapestry.apache.org
> > >
> > >
> >
> >
> > --
> > Regards
> > Jagadesh
> >
>
>
>
> --
> Regards,
> Christophe Cordenier.
>
> Developer of wooki @wookicentral.com
>
--
Regards
Jagadesh
Re: Validation based on condition
Posted by Christophe Cordenier <ch...@gmail.com>.
@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 <ja...@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.cordenier@gmail.com> wrote:
>
> > Hi
> >
> > Try with fielvalidtorsource service to build your conditional
> constraints.
> >
> > Regards
> > Christophe cordenier
> >
> > Le 18 mars 2010 à 06:59, Jagadesh Paladugula <
> jagadeshpaladugula@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-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
> --
> Regards
> Jagadesh
>
--
Regards,
Christophe Cordenier.
Developer of wooki @wookicentral.com
Re: Validation based on condition
Posted by Jagadesh Paladugula <ja...@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.cordenier@gmail.com> wrote:
> Hi
>
> Try with fielvalidtorsource service to build your conditional constraints.
>
> Regards
> Christophe cordenier
>
> Le 18 mars 2010 à 06:59, Jagadesh Paladugula <ja...@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-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
Regards
Jagadesh
Re: Validation based on condition
Posted by Christophe Cordenier <ch...@gmail.com>.
Hi
Try with fielvalidtorsource service to build your conditional
constraints.
Regards
Christophe cordenier
Le 18 mars 2010 à 06:59, Jagadesh Paladugula <jagadeshpaladugula@gmail.co
m> 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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org