WebWork2 auto validation is inconsistent

I’ve been working in WebWork2 lately trying to get a Java web application up and running. A few of the major downsides to WebWork2, making it nearly unusable, are that the documentation is really lacking in almost all areas, there are few examples and the framework does not behave in a consistent manner. My current pain point that illustrates this inconsistent behavior is this:

I wanted to use the WebWork2 auto validation to check my form fields. We’ll being a minimalist, I created my Action class and made it look like this:

public class MyAction implements Action {
 ...
}

I implemented Action because I didn’t really want to extend or implement anything and I figured implementing an interface was the lesser of the two evils. Well, the only problem is that WebWork as a framework doesn’t actually handle redirects or forwards when validation fails. You might think it does, but it doesn’t. Instead it relies on the Action classes to provide this functionality. Since my execute methods was useless since I was using named methods (it actually threw an exception) I kept being forwarded back to the input form after the action method had been called. This isn’t suppose to happen. A proper framework will never call an action method after validation has failed unless it explicit states it will always do so or allows some obvious configuration for controlling this.

As it turns out, if you extend the ActionSupport class instead of implementing the interface directly, things magically start to work. This looks like this:

public class MyAction extends ActionSupport {
 ...
}

If there are validation errors you are magically forwarded to the result named input. Very unexpected behavior from essentially the same class except for the implements/extends clause. So, what this means is that the WebWork2 helper class ActionSupport is actually doing framework work, which forces this class to be extended if you are doing validation. Not ideal in my opinion. This work should always be handled by the framework internally and exposed to the developer via concise configuration if at all.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s