Client validation validation does not work using validate ()

I am doing validation inside the validate () method.

public void validate(){
    if(continent.equals("-1")){
        HttpServletRequest request=ServletActionContext.getRequest();  
        HttpSession session=request.getSession();  
        String s=(String)session.getAttribute("operation");
        if(s.equals("edit"))
                edit();
        else if(s.equals("add"))
                add();
        addFieldError( "Continent", "Continent must be selected");
    }
}

And in jsp (view) the form attribute validate = true is added

<s:form action="add" name="aaa" cssClass="yy" method="post" validate="true">
        <s:textfield name="Code" label="Code" readonly="false" cssClass="defaultTextBox"/>
        <s:textfield name="Name" label="Name" cssClass="defaultTextBox"/>
        <s:select name="Continent" label="Continent" headerKey="-1" headerValue="Select" list="continentlist" cssClass="defaultTextBox"/>
        <s:textfield name="IndepYear" label="Independance Year" cssClass="defaultTextBox" />
        <s:submit value="Save" cssClass="login login-submit" theme="simple"/>
</s:form>

But only server side validation works. My question is: → Can't add client side validation using validate () method?

+2
source share
3 answers

In Struts 2, client-side validation has different meanings and is completely dependent on the type of theme you are using.


SIMPLE, HTML, CSS JavaScript .

, , , ( - - , :)

HTML5 jQuery, .

+1

. validate ... , . JS , .

0

AJAX , struts2-jquery plugin, Showcase :

  • Form Forms with Validation
  • Form Forms with Custome Validation

, , - AJAX.

0

Source: https://habr.com/ru/post/1599078/


All Articles