• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

custom validator and custom tags

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hii plzz tell me how to create our own custom validator and custom tag .

in my struts program i have use validation-user.xml and validation-rule.xml
but this validator are not working

the validation which are working in my program are those which are used in form class method name

public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
{
if (password == null || password.trim().equals(""))
{
errors.add("password", new ActionError("error.password.required"));
}
}

like these validator are working

i want to know why my validator.xml file validation are not working

how i can make Custom Validator and Tag

plzz reply me ....i need help

validator-user.xml

<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.3.0//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_3_0.dtd">

<form-validation>
<formset>
<form name="UserValidationForm">
<field property="loginid" depends="required,maxlength,minlength,mask" >

<msg name="required" key="error.loginid.required" />
<msg name="maxlength" key="error.loginid.length" />
<msg name="minlength" key="error.loginid.length" />
<msg name="mask" key="error.loginid.invalid" />

<arg name="maxlength" key="${var:minlength}" position="0" resource="false"/>
<arg name="maxlength" key="${var:maxlength}" position="1" resource="false"/>

<arg name="minlength" key="${var:minlength}" position="0" resource="false"/>
<arg name="minlength" key="${var:maxlength}" position="1" resource="false"/>

<arg key="UserValidationForm.loginid"/>

<var>
<var-name>minlength</var-name>
<var-value>3</var-value>
</var>
<var>
<var-name>maxlength</var-name>
<var-value>15</var-value>
</var>

<var>
<var-name>mask</var-name>
<var-value>^[a-zA-Z0-9-_]*$</var-value>
</var>

</field>


<field property="password" depends="required,maxlength,minlength,mask">

<msg name="required" key="error.password.required" />
<msg name="maxlength" key="error.password.length" />
<msg name="minlength" key="error.password.length" />
<msg name="mask" key="error.password.invalid" />

<arg name="maxlength" key="${var:minlength}" position="0" resource="false"/>
<arg name="maxlength" key="${var:maxlength}" position="1" resource="false"/>

<arg name="minlength" key="${var:minlength}" position="0" resource="false"/>
<arg name="minlength" key="${var:maxlength}" position="1" resource="false"/>

<arg key="UserValidationForm.password"/>

<var>
<var-name>minlength</var-name>
<var-value>7</var-value>
</var>
<var>
<var-name>maxlength</var-name>
<var-value>20</var-value>
</var>

<var>
<var-name>mask</var-name>
<var-value>^[a-zA-Z0-9]*$</var-value>
</var>

</field>

<field property="retypepassword" depends="validwhen">

<msg name="validwhen" key="error.retypepassword.notmatch" />

<arg key="UserValidationForm.retypepassword"/>

<var>
<var-name>test</var-name>
<var-value>
(password == *this*)
</var-value>
</var>
</field>


<field property="emailaddress" depends="required,email">

<msg name="required" key="error.emailaddress.required" />
<msg name="email" key="error.emailaddress.invalid" />

<arg key="UserValidationForm.password"/>

</field>


</form>
</formset>
</form-validation>


validation entry in struts-config.xml

<message-resources parameter="com.yashdc.strutsexample.resources.ApplicationResources" key="StrutsExample"/>

<plug-in className="org.apache.struts.validator.ValidatorPlugIn" >
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml, /WEB-INF/validator-user.xml"/>
</plug-in>

Form Class which contain validate method this validation are running but not the validation-user.xml

public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();

if (loginid == null || loginid.trim().equals(""))
{
errors.add("loginid", new ActionError("error.loginid.required"));
}
if (password == null || password.trim().equals(""))
{
errors.add("password", new ActionError("error.password.required"));
}
if (retypepassword == null || retypepassword.trim().equals(""))
{
errors.add("retypepassword", new ActionError("error.retypepassword.required"));
}
}
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you write your own validate() method you must still call the super-class's validate() to run the default functionality.
 
What are you doing in my house? Get 'em tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic