Question

I get confused with the concept of validation in Struts. ActionSupport class provides the validation() method

public void validate(){}

which is used to validate the form. But isn't this process working on the server- side?

If it is then, is it fails the concept of validation?

Was it helpful?

Solution

The question isn't clear.

Yes, an action's validate() method obviously validates on the server side.

This is a Good Thing, because data must be validated on the server side, regardless of whether or not any client-side validation occurs. Consider (a) users that have JavaScript disabled, and (b) hand-crafted requests not made through a browser. While (a) is increasingly uncommon, (b) is a legitimate danger.

You cannot rely on JS-only validation.

OTHER TIPS

Isn't this process work on server-side?

Of course, it is a validation on the server-side. By default Struts 2 is configured to use programmatic validation regardless of declarative way.

Both are server-side, Struts2 also has a client-side validation that is using JavaScript. The rightful thing if you use validation both on the client-side and on the server-side.

If your action class extends ActionSupport, you can override the validate() method to use with programmatic validation method used by the framework. In the method body you can implement your custom logic to validate fields.

The validate() method is called by the validation interceptor which is a part of the default interceptor stack defaultStack.

The action should provide the INPUT result to return action errors or field errors.

More about programmatic validation using validation interceptor you can find in this link.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top