The purpose of the org.mentawai.filter.VOFilter (Value-Object Filter) is to populate a object with the values from the action input. This can be useful for form data so instead of providing your actions with a bunch of attributes like firstName, lastName, address, email, etc. you can give it a populated User object. Note that an User is just a POJO (plain old java object).
The way the VOFilter works is that it tries to inject every attribute from the action input into the action through reflection. It will also try to inject values directly into the fields, public or private, if you tell it to do so. So the rule is: first try setter methods (setUsername, setFirstName, etc.), then, if enabled, try to inject into the field (username, firstName) even if the field is private.
Things you should note about the VOFilter:
import org.mentawai.core.*; import org.mentawai.filter.*; public class ApplicationManager extends org.mentawai.core.ApplicationManager { public void loadActions() { ActionConfig ac = new ActionConfig("/Hello", HelloVOFilter.class); ac.addConsequence(SUCCESS, fwd("/show.jsp")); ac.addConsequence(ERROR, fwd("/user.jsp")); addActionConfig(ac); ac.addFilter(new VOFilter(User.class)); // populate a User object and place it in the action input with "org.myprof.User" key // or ac.addFilter(new VOFilter(User.class, "user")); // populate a User object and place it in the action input with "user" key // or ac.addFilter(new VOFilter(User.class, "user", true)); // populate a User object and place it in the action input with "user" key // also try to inject directly into the fields, public or private } }
The org.mentawai.filter.OVFilter (Object-Value filter) is the opposite of the VOFilter. It looks for an object in the action output and tries to extract all its fields and place them into the action output. This can be very useful for example when you want to display all properties of an object inside a html form (see HTML Tags to understand how Mentawai can do this for your automatically, without a single line of code). With the OVFilter, you would load an User from the database and just place it in the action output. The filter will do the dirty work of extracting all properties and placing them in the action output.
Things you should note about the OVFilter:
import org.mentawai.core.*; import org.mentawai.filter.*; public class ApplicationManager extends org.mentawai.core.ApplicationManager { public void loadActions() { ActionConfig ac = new ActionConfig("/Hello", HelloOVFilter.class); ac.addConsequence(SUCCESS, fwd("/show.jsp")); ac.addConsequence(ERROR, fwd("/user.jsp")); addActionConfig(ac); ac.addFilter(new OVFilter("user")); // look for an object with the "user" key in the action output and extract its properties // placing them in the action output. } }
As you have the VOFilter and OVFilter, Mentawai also provides the InjectionFilter and OutputFilter. They behave the same way except that an InjectionFilter tries to inject the input values into the Action (not into a value-object) and the OutputFilter will try to get all properties from the action (not from a value-object).
The InjectionFilter and OutputFilter can be used if you want to forget about the input and output contexts, in other words, all values from the input will be placed in the action and all properties of the action will be placed in the output.
You should note that the Injection/Output filter play an important role when it comes to model-driven actions. With that approach (used by the MyBooks Demo Application), the InjectionFilter will try to inject directly in the model provided by the action and the OutputFilter will try to extract the properties directly from that same model.