A Resolution is a class that takes a servlet request and response objects and redirects, forwards or writes the response contents. Resolutions are executed in the last step of workflow execution.
AbstractAction includes some convenience methods to create common resolution classes:
// forward to /WEB-INF/jsp/[action]/edit.jsp
public Resolution edit() {
return forward("edit.jsp");
}
// forward to /WEB-INF/jsp/[action]/create.jsp
public Resolution create() {
return forward();
}
// redirect to another action
public Resolution delete() {
return redirect(AnotherAction.class, "list").add("id", 1);
}
// deliver a binary file (image,PDF, etc)
public Resolution getFile() {
return send(fileManager.find(id));
}
Redirect a browesr request to other location:
public Resolution myEvent() {
// redirect by class and event name
return redirect(OtherAction.class, "eventName");
// same thing, adding some extra GET parameters
return redirect("Other", "eventName").add("mortgage.id", 15);
// redirect by URI, and make it permanent (301) instead of temporal (302)
return redirect("/foo/bar").permanent();
}
If there are validation errors in this request, they will be saved to a flash context and restored at the end of the next request (after the new event has been executed, but before any resolution execution). That way, they can be displayed as if they happened in the redirected request - for example, to redirect the request to a different action where current validation errors should be displayed.
Forward a request to a file resource. By default, forwards are located inside /WEB-INF/jsp to prevent direct browser invocations:
public class BlogsAction extends AbstractAction {
public Resolution save() {
// forward to a locale-specific location, e.g.: /WEB-INF/jsp/blogs/results_en.jsp
return forwardWithLocale("results.jsp");
// forward to a relative location: /WEB-INF/jsp/blogs/results.jsp
return forward("results.jsp");
// forward to /WEB-INF/jsp/blogs/some/results.jsp
return forward("some/results.jsp");
// forward to "/WEB-INF/jsp/results.jsp"
return forward("/results.jsp");
// forward to /WEB-INF/jsp/blogs/[event].jsp and set some request attributes
return forward()
.set("foo", foo)
.set("bar", bar)
;
}
}
You can set the logging threshold of ForwardResolutionImpl to DEBUG to see the current forward destination.
When using forwardWithLocale("location.jsp") the framework will first look for a resource for the request locale (e.g.: "location_es.jsp"), the default locale (e.g.: "location_en.jsp") or the empty locale ("location.jsp"), in this order.
Intended for cases where the generated response includes very simple HTML generated from Java code:
public Resolution listAjax() throws Exception {
HtmlResolution res = new HtmlResolution();
for (Item item: items){
UrlBuilder url = new UrlBuilder(FooAction.class, "eventName")
.add("id", item.getId());
// print lt;a href="..."
// atributes will only be printed if not null
res.start("a", "href", url.getURL(getRequest()), "title", item.getTitle());
res.print(item.getName()).end("a");
}
return res;
}
Intended for cases where a HTTP error response should be generated.
return new HttpErrorResolution(404);
You may also just throw HttpErrorException instead. Notice that in this case the error message will be logged but not displayed in the HTML error page.
throw new HttpException(400, "Malformed request. GeoPt format is not valid");
Used to return a file to the browser.
// create using a java.io.File instance
return new InputStreamResolution(new File("/tmp/foo.txt");
// create using an open InputStream
return new InputStreamResolution("bar.gif", inputStream);
The Content-Type will be calculated by default using the MIME types registered in MimeUtils, but it can be overriden by invoking resolution.setContentType().