You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Sivaswamynatha K <k....@Kavniya.com> on 2008/01/09 11:14:14 UTC

acessing form values in validation.xml

Hi,

 

Is it possible to access the form variables in the validation.xml file.
I am using Struts 1.2.9

Ie. I have a requirement to enter the year field between 1800 to current
year + years.

 

In validation.xml

<field property="builtYear" depends="mask,validwhen">

<msg resource="true" key="errors.builtYear" name="validwhen" />

      <msg resource="true" key="errors.mask" name="mask" />

      <arg position="0" key="label.mortgageinfo.builtyear" />

????<arg position="1" ?/>                       

                        

      <var>

            <var-name>mask</var-name>

            <var-value>${year}</var-value>

      </var>

      <var>

            <var-name>test</var-name>

            <var-value>((builtYear == null) or ((builtYear >1800) and
(builtYear &lt; futureYear)))</var-value>

      </var>                        

</field>

 

I set the value of futureYear is action and it changes according to the
current year. The validation is fine. Now I want to show the error
message when the validation fails.

The error is just like 

'The built year ranges between 1800 and <customizedvalue>'

 

In message resources 

errors.builtYear= The {0}  ranges between 1800 and {1}

 

 

Regards,

K. Siva.

 

If you win you need not explain ... But if you lose you should not be
there to explain -- Adolf Hitler

 

 


Re: acessing form values in validation.xml

Posted by Laurie Harper <la...@holoweb.net>.
Sivaswamynatha K wrote:
> Hi,
> 
>  
> 
> Is it possible to access the form variables in the validation.xml file.
> I am using Struts 1.2.9
> 
> Ie. I have a requirement to enter the year field between 1800 to current
> year + years.
> 
>  
> 
> In validation.xml
> 
> <field property="builtYear" depends="mask,validwhen">
> 
> <msg resource="true" key="errors.builtYear" name="validwhen" />
> 
>       <msg resource="true" key="errors.mask" name="mask" />
> 
>       <arg position="0" key="label.mortgageinfo.builtyear" />
> 
> ????<arg position="1" ?/>                       
> 
>                         
> 
>       <var>
> 
>             <var-name>mask</var-name>
> 
>             <var-value>${year}</var-value>
> 
>       </var>
> 
>       <var>
> 
>             <var-name>test</var-name>
> 
>             <var-value>((builtYear == null) or ((builtYear >1800) and
> (builtYear &lt; futureYear)))</var-value>
> 
>       </var>                        
> 
> </field>
> 
>  
> 
> I set the value of futureYear is action and it changes according to the
> current year. The validation is fine. Now I want to show the error
> message when the validation fails.
> 
> The error is just like 
> 
> 'The built year ranges between 1800 and <customizedvalue>'
> 
>  
> 
> In message resources 
> 
> errors.builtYear= The {0}  ranges between 1800 and {1}

So what's your question? How to pass in a value for {1}? i.e. what to 
put for the <arg> tag with position="1"? You just need to pass the value 
of futureYear, no?

   <arg position="1" ressource="false" key="futureYear"/>

or possibly key="formName.futureYear" or something, I'm not sure if it 
needs to be fully qualified or not.

L.


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