Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

struts validation

 
kaushik saha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can i validate this type field using xml validation in struts2

the format is NN-NNNNNNN

N is no from (0->9) must be 9 digits in all


 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

for pattern match you have to use regex fpr validation.


like :


<field name="XYZ">
<field-validator type="regex">
<param name="expression">[0-9]-[0-9]</param>
<message>The value of bar2 must be in the format "x, y", where x and y are between 0 and 9</message>
</field-validator>
</field>


For better ref :- http://struts.apache.org/2.x/docs/validation.html#Validation-DefiningValidationRules



 
kaushik saha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where i place this <actionclassname>-validation.xml file
 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

With the package contains your action class.

Like If your Action Abc.java in your com.xyz.action package then your Abc-validation.xml also in your com.xyz.action package.


 
kaushik saha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<!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="taxId">
<field-validator type="regex">
<param name="expression">[0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9]</param>
<message>The value of Tax Id must be in the format "NN-NNNNNNN", where N is number between 0 and 9</message>
</field-validator>
</field>
</validators>

put it in the WEB-INF/classes/pkgname/action/<actionclass name>-validation.xml

and in the jsp page in the form tag write validate="true" ...but still the validation is not working ....

Other than these what i have to do???Please reply me..
 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

You don't have to do any thing just make sure your url Action name.

When it called your action called that class file.

It automatic called validation when Struts get xml of same as your action class.

before check your struts xml mapping.

if you still not get put your URL , jsp and struts xml and action class.


 
kaushik saha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
action class

public String execute() throws Exception {

System.out.println("I am inside execute method of customerMaster update ");
UserLogSetting lobj_ULSetting =(UserLogSetting)session.get("USER_LOG");


customerData= salesManager.getCustomerDetail( customerData,lobj_ULSetting);

System.out.println("I am inside execute method of after customer update");
return SUCCESS;
}

jsp page



<s:form action="updateCustomer" id="custDetailFrm" method="POST" theme="simple" namespace="/salesmgmt" target='_self' validate="true">


strutsxml

<action name="updateCustomer" class="com.hrms.salesmgmt.action.UpdateCustomer">
<result name="input">/salesmgmt/customerDetails.jsp</result>
<result >/salesmgmt/customerDetails.jsp</result>
</action>
 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


Just remove target='_self' validate="true" form form tag.

And what is your validation xml name ???..


And make sure it is at com.hrms.salesmgmt.action.UpdateCustomer package.....



 
kaushik saha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry it is still not working..
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"srk " please check your private messages for an important administrative matter. You can check them by clicking the My Private Messages link above.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic