Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

custom validator and custom tags  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
I have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!