Links

About

Action Consequences

Every Mentawai action returns a String result that is used in the application manager to setup a corresponding Consequence. For example, you might want to allow an action to have two different consequences: one for browsers that need HTML through a JSP template and another one for Ajax requests that need JSON through a Ajax renderer. The action does not care how its output will be processed by the view layer. It can just check some client HTTP request header to return the appropriate result String.

TIP: Instead of doing this client check on every action, you may want to apply a global filter to take care of that.

// redirect to http://www.myapp.com/MYCONTEXT/congrats.jsp?param1=blah&param2=foo
.on(SUCCESS, redir("/congrats.jsp")); // context will be included, as well as any action output values
// redirect to http://www.myapp.com/MYCONTEXT/Book.show.mtw?param1=blah&param2=foo
.on(SUCCESS, redir("/Book.show.mtw")); // context will be included, as well as any action output values
// redirect to a dynamic URL coming from the action, also append any output parameters...
.on(SUCCESS, redir()); // the url will be dynamically generated by the action
// the action must do:
output.setValue(Redirect.REDIRURL_PARAM, theUrlToRedir);
// or the shorter version:
redir(theUrlToRedir);
// to include parameters you just add values to the action output...
// if you don't add anything then no parameters are appended...
output.setValue("param1", "blah");
output.setValue("param2", "foo");
// redirect to http://www.myapp.com/congrats.jsp
.on(SUCCESS, redir("//congrats.jsp")); // context will NOT be included (rarely used!)

You can also redirect to an action config and Mentawai will build the URL from the ActionConfig object: