开发者

Struts2 validation bypass/block, table pagination

I have two action classes, UserAction(methods: login, logout) & EmployeeAction(methods: add, update, view) both have a validate method. It is invoked for every method by default. Is there a way to bypass call to validate method on say logout, as doing so throws an nullpointer exception on fields. Same for view method, that doesn't need any validation.

struts.xml

<action name="*Employee" method="{1}" class="package.EmployeeAction">
    <result name="not_found">/WEB-INF/errors/not_found.jsp</result>
    <result name="success">/WEB-INF/{1}Employee.jsp</result>
</action>

2) how can I implement clien开发者_开发技巧t side validation for 3 jsp pages, add.jsp, view.jsp & update.jsp which all call a method of a single action class?

3) are there any tutorials on how to create table pagination in struts2? I was unable to locate one. documentation? -Nishant.


You can bypass validation for specific method names by adding them to the excludeMethods parameter of the validation and workflow interceptors. If you look at the defaultStack definition, you'll see it's already excluding a few common method names. Just add logout to the list:

        <interceptor-stack name="defaultStack">
            <interceptor-ref name="exception"/>
            <interceptor-ref name="alias"/>
            <interceptor-ref name="servletConfig"/>
            <interceptor-ref name="i18n"/>
            <interceptor-ref name="prepare"/>
            <interceptor-ref name="chain"/>
            <interceptor-ref name="debugging"/>
            <interceptor-ref name="scopedModelDriven"/>
            <interceptor-ref name="modelDriven"/>
            <interceptor-ref name="fileUpload"/>
            <interceptor-ref name="checkbox"/>
            <interceptor-ref name="multiselect"/>
            <interceptor-ref name="staticParams"/>
            <interceptor-ref name="actionMappingParams"/>
            <interceptor-ref name="params">
              <param name="excludeParams">dojo\..*,^struts\..*</param>
            </interceptor-ref>
            <interceptor-ref name="conversionError"/>
            <interceptor-ref name="validation">
                <param name="excludeMethods">input,back,cancel,browse,logout</param>
            </interceptor-ref>
            <interceptor-ref name="workflow">
                <param name="excludeMethods">input,back,cancel,browse,logout</param>
            </interceptor-ref>
        </interceptor-stack>


how can I implement client side validation for 3 jsp pages, add.jsp, view.jsp & update.jsp which all call a method of a single action class?  

All you need to do is set validate = true in form tag in you JSP. You can refer this link

are there any tutorials on how to create table pagination in struts2?

You can try display tags. This tag library have good support for pagination.

Hope this helps

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜