File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Validation framework issue in struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Validation framework issue in struts2" Watch "Validation framework issue in struts2" New topic
Author

Validation framework issue in struts2

deep kulkarni
Greenhorn

Joined: Dec 05, 2007
Posts: 18
Hi,
I am unable to use validation framework of struts,Following are steps in did for this,
1) Add method in form.
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {......
if (getCustomerCode() == null || getCustomerCode().length() < 1) {
errors.add("customerCode", new ActionError("errors.required"));
}
}
2)Add this entry in ApplicationResources.properties
errors.required={0} is required.
fmCustomerMaster.customerCode=Customer Code

3) In Struts_config.xml added,

<controller processorClass="org.apache.struts.action.RequestProcessor"/>

<message-resources parameter="ApplicationResources" />

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


4) In validator.xml added.

<form-validation>
<formset>
<form name="fmCustomerMaster">
<field property="customerCode" depends="required">
<arg0 key="fmCustomerMaster.customerCode"/>
</field>
</form>
</formset>
</form-validation>

But when form is submitted that time validate() method is called and " {0} is required ".is Print .
It is not replacing {0} parameter by arg specified,It means it is not using validator.xml because if i remove all code from this xml file.it is still printing same msg " {0} is required " .
Am i wrong in any steps above? Please let me know.
deep kulkarni
Greenhorn

Joined: Dec 05, 2007
Posts: 18
Validator.xml contain Following code

<?xml version="1.0" encoding="UTF-8"?>
<xml-body>
<form-validation>
<formset>
<form name="fmCustomerMaster">
<field property="customerCode" depends="required">
<arg0 key="fmCustomerMaster.customerCode"/>
</field>
</form>
</formset>
</form-validation>
</xml-body>


Is this file and validator-rules.xml file need any <!DOCTYPE ...> tag
Please let me know.
siddhu Math
Ranch Hand

Joined: Aug 10, 2006
Posts: 46
check whether the action tag's validate=true property is set for the particular action in your strutsconfig.xml.
for example:
.
deep kulkarni
Greenhorn

Joined: Dec 05, 2007
Posts: 18
Yes i have given validate="true". i think i am missing <!DOCTYPE > tag for validator-rules.xml,validator.xml

Please let me know if it is rally needed.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

This isn't Struts 2.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validation framework issue in struts2
 
Similar Threads
LookupDispatch action with validator
errors messages from ActionForm validate are not displaying
validation problem in struts
Struts validator framework, please help
Struts Validator Configuration