Bhadra
Bhadra

Reputation: 1181

can i override struts validate method inside action class execute method?

I am new to Struts framework, currently I am developing a web based application using struts framework.

As we know that, in Struts application we can override the validate() in our user-defined Formbean-class to validate the user input, similarly can I override it inside my Action class's execute()?

If I can, after adding the ActionError object to the ActionErrors object, what all I need to do? Just help me with explanation.

Upvotes: 0

Views: 1962

Answers (1)

JB Nizet
JB Nizet

Reputation: 691655

You can't override it, because Action doesn't define any validate() method. But you can perform validation in an action, yes:

public ActionForward execute(ActionMapping mapping,
                             ActionForm form,
                             HttpServletRequest request,
                             HttpServletResponse response) {
    ...
    ActionMessages errors = doSomeValidation();
    if (!errors.isEmpty()) {
        saveErrors(request, errors);
        return mapping.getInputForward();
    }
    ...
}

Upvotes: 2

Related Questions