Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » how to use snap for design submenus
how to use snap for design submenus [message #644541] Mon, 13 December 2010 08:03 Go to next message
Gary Lee is currently offline Gary LeeFriend
Messages: 4
Registered: December 2010
Junior Member
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 #644633 is a reply to message #644541] Mon, 13 December 2010 14:49 Go to previous messageGo to next message
Dmitry Sklyut is currently offline Dmitry SklyutFriend
Messages: 279
Registered: January 2010
Senior Member
SnapTag is a fairly simple thing. It only reads in ServiceRegistration properties, i.e. properties that services is published with.

By default you will get following set:
// every property from META-INF/snap.properties
// plus
serviceProperties.put("snap.host.id", Long.toString(hostBundle.getBundleId()));
            serviceProperties.put("snap.context.path", snap.getContextPath());
            serviceProperties.put("snap.name", (String) this.context.getBundle().getHeaders().get("Bundle-Name"));



"snap.order" property in snap.properties can be used to control publication "service.ranking".

Having said that, the way menu.bar sample is structured, it just read in the properties and builds the menu in jsp page:
<div id="primary-navigation">
		<div id="primary-left">
			<ul>
				<snaps:snaps var="snaps">
					<c:forEach var="snap" items="${snaps}">
						<li><a href="<c:url value="${snap.contextPath}${snap.properties['link.path']}"/>">
							${snap.properties['link.text']}</a>
						</li>
					</c:forEach>
				</snaps:snaps>
			</ul>
		</div>
		<div id="primary-right">
		</div>
	</div>


Nested menues can be done by customizing jsp code to account for nested properties (any way you want to code this).

Hope this helps.

Regards,
Dmitry
Re: how to use snap for design submenus [message #644784 is a reply to message #644633] Tue, 14 December 2010 08:56 Go to previous messageGo to next message
Gary Lee is currently offline Gary LeeFriend
Messages: 4
Registered: December 2010
Junior Member
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
Re: how to use snap for design submenus [message #644831 is a reply to message #644784] Tue, 14 December 2010 11:34 Go to previous messageGo to next message
Dmitry Sklyut is currently offline Dmitry SklyutFriend
Messages: 279
Registered: January 2010
Senior Member
Hi Gary,

So you are looking for a snap to have a "deep" link, i.e. more like a servlet path?

Sounds useful. Can you create a jira issue?

Regards,
Dmitry
Re: how to use snap for design submenus [message #645704 is a reply to message #644831] Mon, 20 December 2010 04:07 Go to previous messageGo to next message
Gary Lee is currently offline Gary LeeFriend
Messages: 4
Registered: December 2010
Junior Member
Well, in short,

I want to use "Snap" to show the Portal menus. However, if you use the Snaps-tags, we *ONLY* gets the snap bundles. Of course, you can make a customized attributes into snap.properties, but I think the Snap-ContextPath is a good place to decide the hierarchy of menu structure.

i add SnapsTree and SnapsNode and to modify Snap and SnapsTag for this issue.

for Example

cat bundle: Snap-ContextPath:/cat
cat1 bundle: Snap-ContextPath:/cat/cat1
cat2 bundle: Snap-ContextPath:/cat/cat2
dog bundle: Snap-ContextPath:/dog
dog1 bundle: Snap-ContextPath:/dog1

in header.jsp you can use
<snaps:snaps var="snaps">

 <c:set var="rootNode" value="${snapstree.rootElement}"/>
 
 <ul>
	 <c:forEach items="${rootNode.children}" var="node">
	 	<li><a href="<c:url value="${node.data.contextPath}${node.data.linkPath}"/>">${node.data.linkText}</a></li>
	 	<c:if test="${not empty node.children}"><ul></c:if>
	 	<c:forEach items="${node.children}" var="subNode">
	 		<li><a href="<c:url value="${subNode.data.contextPath}${subNode.data.linkPath}"/>">${subNode.data.linkText}</a></li>
	 	</c:forEach>
	 	<c:if test="${not empty node.children}"></ul></c:if>
	 </c:forEach>
 </ul>
</snaps:snaps>


You can use the menu CSS definitions to translate the menu data as you want.
Re: how to use snap for design submenus [message #646036 is a reply to message #645704] Tue, 21 December 2010 16:39 Go to previous messageGo to next message
Dmitry Sklyut is currently offline Dmitry SklyutFriend
Messages: 279
Registered: January 2010
Senior Member
Gary,

Can you please create a bugzilla issue to track this? Refer back to this post.

Thank you!

Dmitry
Re: how to use snap for design submenus [message #731319 is a reply to message #646036] Fri, 30 September 2011 16:08 Go to previous messageGo to next message
Chris Frost is currently offline Chris FrostFriend
Messages: 230
Registered: January 2010
Location: Southampton, England
Senior Member

Reposted form Bugzilla,

I've done some work on this and want some other peoples opinion. I see two options, we either support snaps with more than one path element in their context path as suggested here or we support nested snaps. So in this case we would attach the cat1 and cat2 snaps to the cat snap as their host making them grandchildren of the top level host.

I don't want to support both as there is too much potential for multiple snaps being about to respond to a request and there isn't a logical way to decide which snap would take priority. If we go with the grandchild approach we would place a ban on snaps with more than one path element in their context path. I prefer this approach but wanted to give people the chance to argue with me.

Chris.


------------------------------------------------
Chris Frost, Twitter @cgfrost
Springsource, a divison of VMware.
Re: how to use snap for design submenus [message #731370 is a reply to message #731319] Fri, 30 September 2011 18:38 Go to previous messageGo to next message
Dmitry Sklyut is currently offline Dmitry SklyutFriend
Messages: 279
Registered: January 2010
Senior Member
Snap with a child snap? Interesting. Never thought about it that way. Would the snap that is a child of snap know the BSN of the host snap? i.e. How would the grand snap bind to host snap?

I thought it would be easier to change how snap url is resolved vs. nesting. I believe code currently cuts off the last part of the uri and use that to look up a snap. That could be changed to use a "best match" strategy and keep one level of nesting.

Have to think this through a bit. Interesting approach.
Re: how to use snap for design submenus [message #733624 is a reply to message #731370] Wed, 05 October 2011 08:45 Go to previous message
Chris Frost is currently offline Chris FrostFriend
Messages: 230
Registered: January 2010
Location: Southampton, England
Senior Member

Hi,

The Grand snap wouldn't bind to the host, it would bind to it's parent and have no idea that it's a grand snap and the host would have no idea it's got grand snaps.


------------------------------------------------
Chris Frost, Twitter @cgfrost
Springsource, a divison of VMware.
Previous Topic:Deploying Spring Soap ws war fails in Virgo - Error instantiating ... MessageDispatcServlet
Next Topic:Virgo Experience Report
Goto Forum:
  


Current Time: Fri Apr 26 12:57:35 GMT 2024

Powered by FUDForum. Page generated in 0.45004 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top