• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validation framework issue in struts2

 
deep kulkarni
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check whether the action tag's validate=true property is set for the particular action in your strutsconfig.xml.
for example:
.
 
deep kulkarni
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This isn't Struts 2.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic