简体   繁体   中英

struts2 validate

In Struts2 you can change the method used for execution for an action by changing the method attribute in the following line:

<action name="registerVal" class="cz.vutbr.fit.pishotel.model.action.Register" method="execute">

Is it possible to change the validation method used as well, or is the validate method name hardcoded.

It hard coded in the following way. If you have:

<action name="registerVal" class="cz.vutbr.fit.pishotel.model.action.Register" method="myMethod">

Then the validation interceptor will call

public void validateMyMethod() {

if (someValue == null) {

addFieldError("myField","myMessage");

}

}

If there are errors in the fieldErrors collection then INPUT will be returned for registerVal

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM