You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Jone.hwk" <jo...@yahoo.com.cn> on 2005/08/12 05:06:52 UTC

How to specify a var to validators

Hi,

I'd like to change the "maxLength" at runtime for the validator settings: 
validators="validators:required,maxLength=page.config.maxLength",but exception 
always thrown:

Error initializing validator 'maxLength' (class 
com.test.tapestry.valid.MaxLength): Unable to convert 'page.config.maxLength' 
to type int (for property maxLength of object 
com.test.tapestry.valid.MaxLength@1ebf5c): 'page.config.maxLength' 

Is there a way to fix the problem?
thanks
Jone.hwk


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: How to specify a var to validators

Posted by Kevin Menard <km...@servprise.com>.
On Aug 16, 2005, at 6:04 PM, Kevin Menard wrote:

> Hi Paul,
>
> How would you go about making form components dynamically  
> requirable?  The Required class does not allow its required  
> property to be changed.  I'd imagine there's some easy solution to  
> this, but I'm scratching my head trying to figure it out.  Any help  
> would be appreciated.

In case anyone is interested, I came up with a solution.  The idea is  
to dynamically add or remove the validator, rather than try to modify  
its state.  An example of how I did it is below:

In the spec:

     <component id="blah" type="TextField">
         <binding name="displayName" value="literal:Blah"/>
         <binding name="hidden" value="true"/>
         <binding name="validators" value="blahRequired"/>
     </component>

In the page class:

     @Bean
     public abstract Required getRequired();

     .
     .
     .

     public Validator getBlahRequired()
     {
         if (true == someCondition)
         {
             return getRequired();
         }

         return null;
     }

This seems to be working pretty well now.  I like being able to move  
all of that logic into the page class too, rather than having it  
kicking around in the spec.

-- 
Kevin

Re: How to specify a var to validators

Posted by Kevin Menard <km...@servprise.com>.
Hi Paul,

How would you go about making form components dynamically  
requirable?  The Required class does not allow its required property  
to be changed.  I'd imagine there's some easy solution to this, but  
I'm scratching my head trying to figure it out.  Any help would be  
appreciated.

Thanks,
Kevin

On Aug 12, 2005, at 2:12 PM, Paul Ferraro wrote:

> The validators binding is meant for static initialization  
> parameters only.  If you want to use dynamic initialization  
> parameters, use the bean approach that you used in Tapestry 3.
> e.g.
>
> <bean name="required"  
> class="org.apache.tapestry.form.valid.Required"/>

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: How to specify a var to validators

Posted by Paul Ferraro <pa...@gmail.com>.
The validators binding is meant for static initialization parameters 
only.  If you want to use dynamic initialization parameters, use the 
bean approach that you used in Tapestry 3.
e.g.

<bean name="required" class="org.apache.tapestry.form.valid.Required"/>
<bean name="maxLength" class="org.apache.tapestry.form.valid.MaxLength">
    <set name="maxLength" value="page.config.maxLength"/>
</bean>

<component id="..." type="TextField">
    <!-- ... -->
    <property name="validators" value="{beans.required, beans.maxLength}"/>
    <!-- ... -->
</component>

Jone.hwk wrote:

>Hi,
>
>I'd like to change the "maxLength" at runtime for the validator settings: 
>validators="validators:required,maxLength=page.config.maxLength",but exception 
>always thrown:
>
>Error initializing validator 'maxLength' (class 
>com.test.tapestry.valid.MaxLength): Unable to convert 'page.config.maxLength' 
>to type int (for property maxLength of object 
>com.test.tapestry.valid.MaxLength@1ebf5c): 'page.config.maxLength' 
>
>Is there a way to fix the problem?
>thanks
>Jone.hwk
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: How to specify a var to validators

Posted by "Jone.hwk" <jo...@yahoo.com.cn>.
I think the tapestry cannot recognize the var "page.config.maxLength".

Jone.hwk


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


RE: How to specify a var to validators

Posted by Patrick Casey <pa...@isdsd.com>.
	Sure sounds like your property (maxLength) isn't an int. What's the
property getter look like?

	--- Pat

> -----Original Message-----
> From: news [mailto:news@sea.gmane.org] On Behalf Of Jone.hwk
> Sent: Thursday, August 11, 2005 8:07 PM
> To: tapestry-user@jakarta.apache.org
> Subject: How to specify a var to validators
> 
> Hi,
> 
> I'd like to change the "maxLength" at runtime for the validator settings:
> validators="validators:required,maxLength=page.config.maxLength",but
> exception
> always thrown:
> 
> Error initializing validator 'maxLength' (class
> com.test.tapestry.valid.MaxLength): Unable to convert
> 'page.config.maxLength'
> to type int (for property maxLength of object
> com.test.tapestry.valid.MaxLength@1ebf5c): 'page.config.maxLength'
> 
> Is there a way to fix the problem?
> thanks
> Jone.hwk
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org