Client side validation not working using validate()

前端 未结 3 1585
挽巷
挽巷 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.

提交回复
热议问题