• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

struts validation

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
where i place this <actionclassname>-validation.xml file
 
Nishan Patel
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry it is still not working..
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
And then the flying monkeys attacked. My only defense was this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic