开发者

Struts2 Validation for Wildcard methods

I have a situation where i have 2 methods in the same action class, method1 and method2. Below is my action mappings in struts.xml

  < action name="actionName_*" class="sample.input.SubmitTest" method="{1}">
   < interceptor-ref name="defaultStak" />  
   < result name="input">info.jsp< result ends>
   < result name="success">info.jsp< result ends&g开发者_如何学运维t;
   < result name="error">error.jsp< result ends>
  < action ends>

Validation rules for method1 and method2 are different so i have 2 validation xml files. 1: actionName_method1-validation.xml 2: actionName_method2-validation.xml

This configuration is as per http://struts.apache.org/2.1.6/docs/action-configuration.html#ActionConfiguration-DynamicMethodInvocation

I invoke these methods from a JSP as shown below,

< s:form action="actionName_" method="post">
    <!-- here goes the fields to be submitted -->
    <s:submit type="simple" method="method1" value="execute1"/>
    <s:submit type="simple" method="method2" value="execute2"/>
< s:form  end tag>

However for some reason the validations are not getting executed. Am I missing something here, can anyone please help?


The mistake was in the s:submit, below is the correct s:submit which worked

< s:form action="actionName_" method="post">
    < s:submit type="simple" action="actionName_method1" value="execute1"/>
    < s:submit type="simple" action="actionName_method2" value="execute2"/>
< s:form  end tag>


I was looking for an answer to this question, but the one that appeared here wasn't solving my problem.

To solve the problem, you have to apply the @Rajesh solution (use action attributes instead of method in the <s:submit> tag) and you have to rename the validation file so that it fulfills the following rule:

<actionClass>-<actionAlias>-validation.xml

So the validation files, in this case, should be renamed to:

SubmitTest-actionName_method1-validation.xml
SubmitTest-actionName_method2-validation.xml

as the action class is SubmitTest.

I hope this answer can help others with the problem of XML validation with wildcard methods.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜