how to use snap for design submenus [message #644541] |
Mon, 13 December 2010 03:03  |
Eclipse User |
|
|
|
I already tested the Snap menu-bar sample, if i want to make submenu of cat-menu or dog-menu.
cat-menu | dog-menu
-- cat1 -- dog1
-- cat2 -- dog2
-- cat3 -- dog3
Is the snap supported it ? or Should I re-code the SnapTag.java with customised infomations to make it .
Thanks .
|
|
|
|
Re: how to use snap for design submenus [message #644784 is a reply to message #644633] |
Tue, 14 December 2010 03:56   |
Eclipse User |
|
|
|
Thanks Dmitry,
My thought, i can use the Snap-ContextPath for split the categories as submenus.
for example
dog bundle
Snap-ContextPath: /dog
dog1 bundle
Snap-ContextPath: /dog/dog1
dog2 bundle
Snap-ContextPath: /dog/dog2
When I found the /dog/dog1 as url pattern, i will dispatch to dog1 bundle, and i will know it should display submenu under dog bundle.
However, the SnapUtil.java is substring the *ONLY* first "/" as contextPath, I can't set /dog/dog1 as contextPath.
So that, I modify the SnapUtils.determineSnapContextPath method
public static String determineSnapContextPath(HttpServletRequest request, int cnt) throws Exception {
// TODO Move to HostUtils, or similar
String result;
String includeServletPath = (String)request.getAttribute("javax.servlet.include.servlet_path");
if (includeServletPath != null) {
result = includeServletPath;
} else {
result = request.getServletPath();
}
int index = result.length();
for(int i=0; i<cnt; i++) {
index = result.lastIndexOf(PATH_ELEMENT_SEPARATOR, index);
if( index <= 0 ) {
throw new Exception("the '/' is ended ");
}
}
if (index > -1) {
result = result.substring(0, index);
}
return result;
}
and RequestRouter.findSnap
private Snap findSnap(HttpServletRequest request) {
int i = 0 ;
Snap snap = null;
try {
while(true) {
String contextPath = SnapUtils.determineSnapContextPath(request, i);
snap = this.snapRegistry.findSnapByContextPath(contextPath);
if( snap == null) {
i++;
} else {
break;
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return snap;
}
I think that this modification is not good, just for my work, the better solution is to use URL-pattern matcher to determine the contextPath with multiple "/" .
Regards
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.39687 seconds