Vita Rara: A Life Uncommon

Difficult to use with input validators

This interceptor seemed like a good idea for the use case I'm implementing in my application - a two-step user registration process. What I'm finding is that, in practice, the ConversationInterceptor is difficult to use because it is interacting badly with Struts2 input validators. It forces you to structure your input validation configuration in one specific way.

Allow me to explain further.

I started off with two action classes, two separate JSPs, and two validation.xml configuration files. The ConversationScopeAware interface has an unstated requirement that all aspects of the conversation take place within one action class, as the lifecycle of the ConversationModel is determined by the prepareConversationModel() and isConversationFinished() methods in the ConversationScopeAware interface. (I assume if I use two separate action objects, each will get a separate ConversationModel object, sort of defeating the purpose of the whole thing).

So, I refactored to put the entire conversation into one action class. Because the Struts2 validation mechanism is hardwired to go to the "input" result on any validation error, I have to combine all the user forms into one JSP as well. Furthermore, I also have to put the input validation into one .xml file.

At this point, only a subset of the input fields are displayed to the user at any step. But the Struts validator validates them all at every step, flagging non-existent fields as not having valid input.

To work around this limitation, I can implement separate methods on the action object for each step in the conversation, but I'm then forced to configure separate validation configuration files for each method in my action (e.g. action-method-validation.xml).

So, the options for how I use and configure input validations are somewhat limited, unless you can see an alternative that I'm missing (which could be possible, as I am a Struts2 neophyte).

I'd like to see some support for extending conversations across action classes. That extra bit of flexibility would make the ConversationInterceptor play a bit nicer with the rest of Struts2.

Reply

Please solve the math problem above and type in the result. e.g. for 1+1, type 2
  • Allowed HTML tags: <a> <img> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <h1> <h2> <h3>
  • Lines and paragraphs break automatically.
More information about formatting options