Java Reference
In-Depth Information
The DefaultViewActionBean for Going Straight to JSPs
If you've been using the “preaction” pattern that we discussed
way back on page 38 , you always make sure that requests first
go through an action bean before being forwarded to a JSP.
For a “stand-alone” JSP that doesn't need an action bean, you
don't have to create an action bean just to forward to the JSP.
Stripes has an internal DefaultViewActionBean that tries to find a
JSP, according to a default set of patterns, if the URL did not
match any existing action beans.
For the /path/SomeView.action URL, Stripes looks for the following
JSPs, in order, and uses the first one that it finds:
/path/SomeView.jsp
/path/someView.jsp
/path/some_view.jsp
If none of the paths matches an existing JSP, then you get the
usual ActionBeanNotFoundException .
We've been putting our JSPs under /WEB-INF/jsp . Prepending this
to each path that Stripes attempts is a simple matter of overrid-
ing a method in NameBasedActionResolver :
Download defaultview/src/stripesbook/ext/MyActionResolver.java
package stripesbook.ext;
public class MyActionResolver extends NameBasedActionResolver {
@Override
protected List<String> getFindViewAttempts(String url) {
List<String> defaultViews =
super .getFindViewAttempts(url);
List<String> customViews =
new ArrayList<String>(defaultViews.size());
for (String view : defaultViews) {
customViews.add("/WEB-INF/jsp" + view);
}
return customViews;
}
}
You can further customize what happens when an action bean
is not found by overriding the findView ( ) and handleActionBean-
NotFound ( ) methods of NameBasedActionResolver .
 
 
Search WWH ::




Custom Search