You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by tallurisuresh <su...@gmail.com> on 2007/06/12 07:09:36 UTC

Please sugest how to do the macro validation in velocity

Hi,
I am using the velocity for UI purpose.when i am developing the velocity
pages i am using the macros. now i am validating the velocity page where i
am using the macro's those fields are not validating. I am using the
struts2.0.6 and tomcat6.0

. I am writing the macro in my velocity page.
#macro (stexttelfield $label1 $label2 $label3)
        <input type="text" name="$label1" size="4">-
        <input type="text" name="$label2" size="4">-
        <input type="text" name="$label3" size="4">
#end

And I am writing the validation.xml file
<!DOCTYPE validators PUBLIC
        "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
        "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">

<validators>
    <field name="username">
        <field-validator type="requiredstring">
            <message key="requiredstring"/>
        </field-validator>
         
    </field>
    <field name="password">
        <field-validator type="requiredstring">
            <message key="requiredstring"/>
        </field-validator>
    </field>
    <field name="password1">
        <field-validator type="requiredstring">
            <message key="requiredstring"/>
        </field-validator>
   
</validators>

The struts.xml file action is

<action name="Login" class="example.Login">
            <result type="velocity">example/Login.vm</result>
            <result type="redirect-action">Menu</result>
        </action>


But the macro fields are not recognize by validation.xml file. so please
suggest me the solution

Regards
suresh 
-- 
View this message in context: http://www.nabble.com/Please-sugest-how-to-do-the-macro-validation-in-velocity-tf3905513.html#a11073031
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Please sugest how to do the macro validation in velocity

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
It's important to understand that S2 validation applies to objects, not 
to the html fields in your form.
That is, first the setters in your action are called, then the validator 
calls the getters to check the values.  If the parameters aren't 
reaching your action then validation will fail.

There's two things that could be going wrong from your description.
 1. the validation.xml is not being found because you have placed it in 
the wrong location; or
 2. validation is failing and you're getting the "input" result.

Assuming you have the second problem, you need to ensure the input names 
your macro creates correctly match the property names expected for your 
action.
You can check this by looking at the generated HTML.  If your input 
names don't match the property names (username, password, password1) the 
values won't be set in your action and validation will fail.  Secondly 
check that your action contains getUsername(), getPassword() and 
getPassword1() exactly (and their setters) because it's case sensitive.

The velocity macro itself is not the problem (provided you're calling it 
correctly).

- Jeromy Evans

tallurisuresh wrote:
> Hi,
> I am using the velocity for UI purpose.when i am developing the velocity
> pages i am using the macros. now i am validating the velocity page where i
> am using the macro's those fields are not validating. I am using the
> struts2.0.6 and tomcat6.0
>
> . I am writing the macro in my velocity page.
> #macro (stexttelfield $label1 $label2 $label3)
>         <input type="text" name="$label1" size="4">-
>         <input type="text" name="$label2" size="4">-
>         <input type="text" name="$label3" size="4">
> #end
>
> And I am writing the validation.xml file
> <!DOCTYPE validators PUBLIC
>         "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
>         "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
>
> <validators>
>     <field name="username">
>         <field-validator type="requiredstring">
>             <message key="requiredstring"/>
>         </field-validator>
>          
>     </field>
>     <field name="password">
>         <field-validator type="requiredstring">
>             <message key="requiredstring"/>
>         </field-validator>
>     </field>
>     <field name="password1">
>         <field-validator type="requiredstring">
>             <message key="requiredstring"/>
>         </field-validator>
>    
> </validators>
>
> The struts.xml file action is
>
> <action name="Login" class="example.Login">
>             <result type="velocity">example/Login.vm</result>
>             <result type="redirect-action">Menu</result>
>         </action>
>
>
> But the macro fields are not recognize by validation.xml file. so please
> suggest me the solution
>
> Regards
> suresh 
>   


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