Skip to content


Experiencing Spring WebFlow, part 3

In my third part of this learning path, I’d like to discuss the way I handle my reference data.

Reference data is extra data that is needed by a form. Typically this is stuff like the options in a select, things that are not provided by the form backing bean.

3. ReferenceDataActions

In order to create a maintable, centralised pool of reference data, I recommend to use the following guidelines:

  • Create a MultiAction called ReferenceDataActions.
  • Create for each backing bean (or each class of backing bean) an initXXX, where XXX is the class of the backing bean.
  • Create for each type of reference data a private method, that returns void. In the private method you put only 1 list or object onto the context. Call the methods something like putYYY, where YYY is the name of the class of reference data you are putting on.
  • In the initXXX methods, you delegate to the private methods the types you need.

Take a look at following example:

public Event initCustomer(RequestContext context) {
putCustomerTypes(context);
putCountries(context);
return success();
}
public void putCountries(RequestContext context) {
context.getRequestScope().put(//INSERT CODE HERE
}

This way of defining the actions will give you an enormous amount of flexibility and maintainability.
When designing your application, you will need to ask yourself: What if something changes?

What if I need to put something new onto the context as referenceData? You just add the method to the initXXX method.
What if I need to change to source of a referenceData? You can just change the putYYY method.

Keeping referenceData out of your real Action classes, is great to keep those classes as small as possible.
The ReferenceDataActions class can grow quite big, but thats ok! Since the implementation inside the class is kept to a bare minimum (referenceData hardly ever needs logic), the class is not overcomplicated. Exposing only the init methods forces you to utilise only the methods you have control over, which you can alter without changing the API.

But as always, I’m open to discussion!

Posted in Spring, WebFlow.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.