"Or do you really need to pass through an action bean?"
I implemented this a while back, here it is.. questions or comments are
welcome.
public class BaseActionBean<ActionBeanContext extends BaseActionBeanContext>
implements ActionBean, ValidationErrorHandler {
public void setContext(net.sourceforge.stripes.action.ActionBeanContext
actionBeanContext) {
@SuppressWarnings("unchecked")
ActionBeanContext context = (ActionBeanContext)
actionBeanContext;
this.context = context;
if (getContext().getBreadCrumbTrailSize() > 0) { // if
subclass wants bread crumb trail
getContext().addBreadCrumb();
// we'll keep it for them.
}
}
}
public class BaseActionBeanContext extends ActionBeanContext {
/**
* Recipe for breadcrumbs. Uses a linked list with a size limited by
* subclass to store the previous http requests written as a GET
string. The add
* method is called in set context.
*/
public void addBreadCrumb() {
Class<? extends ActionBean> actionBeanType =
getRequestedActionBeanType();
if (actionBeanType == null
|| !
actionBeanType.isAnnotationPresent(SkipBreadCrumb.class)) {
addBreadCrumb(urlUtil.postParamsToGetString(getRequest(), false));
}
}
public LinkedList<String> getBreadCrumbs() {
LinkedList<String> breadCrumbs =
getSesAttr(AttrNames.SES_BREAD_CRUMBS);
if (breadCrumbs == null) {
breadCrumbs = new LinkedList<String>();
setBreadCrumbs(breadCrumbs);
}
return breadCrumbs;
}
private void addBreadCrumb(String breadCrumb) {
LinkedList<String> breadCrumbs = getBreadCrumbs();
if (breadCrumbs.size() >= getBreadCrumbTrailSize()) {
breadCrumbs.remove();
addBreadCrumb(breadCrumb);
return;
}
breadCrumbs.add(breadCrumb);
}
private void setBreadCrumbs(LinkedList<String> breadCrumbs) {
setSesAttr(AttrNames.SES_BREAD_CRUMBS, breadCrumbs);
}
/**
* Off by default, override & increase size to the desired number to
enable.
*/
protected int getBreadCrumbTrailSize() {
return 0;
}
}
public class UrlUtil {
private static Set<String> paramsToOmit;
static {
paramsToOmit = new HashSet<String>();
paramsToOmit.add(StripesConstants.URL_KEY_FLASH_SCOPE_ID);
}
public String postParamsToGetString(HttpServletRequest request, boolean
encode) {
StringBuffer sb = new StringBuffer();
sb.append(request.getServletPath());
@SuppressWarnings("unchecked")
Map<String, String[]> params = request.getParameterMap();
if (params != null && !params.isEmpty()) {
sb.append('?').append(paramMapToQueryString(params));
}
return encode ? encode(sb.toString()) : sb.toString();
}
private StringBuffer paramMapToQueryString(Map<String, String[]>
params) {
StringBuffer sb = new StringBuffer();
for (Entry<String, String[]> entry : params.entrySet()) {
String key = entry.getKey();
if (paramsToOmit.contains(key)) {
continue;
}
String[] value = entry.getValue();
for (String aValue : value) {
if ( ! "".equals(aValue)) {
sb.append(key).append('=').append(aValue).append('&');
}
}
}
if (sb.length() > 0) {
sb.setLength(sb.length() - 1);
}
return sb;
}
public String encode(String plainText) {
try {
return URLEncoder.encode(plainText, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException(e);
}
}
}
/**
* Used to tag certain actions that shouldn't show up
* in the bread crumb trail (login/logout, etc)
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface SkipBreadCrumb {
}
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Poitras Christian
Sent: Tuesday, April 29, 2008 9:18 AM
To: 'Stripes Users List'
Subject: Re: [Stripes-users] history.back() using stripes
Can you use javascript?
Or do you really need to pass through an action bean?
Christian
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of SivaKumarl
Sent: Saturday, April 26, 2008 2:05 AM
To: [email protected]
Subject: [Stripes-users] history.back() using stripes
Hi Friends,
Please tell how to implement history.back() functionality in stripes.
Thanks,
Siva
--
View this message in context:
http://www.nabble.com/history.back%28%29-using-stripes-tp16909748p16909748.html
Sent from the stripes-users mailing list archive at Nabble.com.
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss
this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users