Client side validation not working using validate()

前端 未结 3 1588
挽巷
挽巷 2021-01-22 15:36

I am doing validation inside validate() method.

public void validate(){
    if(continent.equals(\"-1\")){
        HttpServletRequest request=ServletActionContext         


        
相关标签:
3条回答
  • 2021-01-22 16:13

    In Struts 2, Client Side Validation has different meanings, and totally depends on the type of theme you are using.

    1. With XHTML (default) and CSS XHTML, you can use the

      • Pure JavaScript Client Side Validation

      that is totally client side, Javascript based and doesn't communicate with the server.

    2. With the AJAX theme instead, you can run the

      • AJAX Client Side Validation

      that will contact the server, running the whole validation Stack, and (to answer your question) running your validate() methods too.


    I personally prefer to use the SIMPLE theme, completely handling the HTML, the CSS and the JavaScript on my own.

    Since the server-side validation is mandatory, the client-side validation is to be considered just a surplus, positive for making the page more user-friendly, and to reduce the network traffic in high users environment (you block unsuccessfull - but legit - requests before they go through the wire :)

    Consider using HTML5 types with fallback on jQuery, especially if you are targeting the mobile.

    0 讨论(0)
  • 2021-01-22 16:19

    actually you shouldn't mix up server side and client side code. validate method can be invoked only in server side... So there is no way to use this method on client side. You need to write your own JS side validation as the same as server side validation.

    0 讨论(0)
  • 2021-01-22 16:19

    It is possible to perform AJAX validation using your server side code using struts2-jquery plugin , as shown in the Showcase under:

    • Form Forms with Validation
    • Form Forms with Custome Validation

    The example that might interest you more is Form Submit without AJAX.

    0 讨论(0)
提交回复
热议问题