掲示板

Problems detecting a selected nav item in velocity template

13年前 に E S によって更新されました。

Problems detecting a selected nav item in velocity template

Junior Member 投稿: 38 参加年月日: 10/04/21 最新の投稿
I am having a problem in my navigation.vm template. Here is the code for the site's navigation:


<ul>
	#foreach ($nav_item in $nav_items)
		#if ($nav_item.isSelected())
			#set ($nav_item_class = "selected")
			<b>Selected!</b>
		#else
			#set ($nav_item_class = "")
		#end

		#if ($nav_item.getName() != "Home")
			<li class="$nav_item_class">
				<a href="$nav_item.getURL()" $nav_item.gettarget()><span>$nav_item.getName()</span></a>
			</li>
		#end
	#end
</ul>


For some reason, none of my navigation items on the site ever get the "selected" class assigned to it. I am having a lot of trouble figuring out why. Can anyone see a problem with my template?
12年前 に Robert Kornmesser によって更新されました。

RE: Problems detecting a selected nav item in velocity template

Junior Member 投稿: 39 参加年月日: 11/11/03 最新の投稿
Same problem here!
In portal_normal.vm, i include navigation 2 times. First time isSelected(() works as desired. second time not.
WHY?
11年前 に Bradley Wood によって更新されました。

RE: Problems detecting a selected nav item in velocity template

11年前 に Mason Stein によって更新されました。

RE: Problems detecting a selected nav item in velocity template

Junior Member 投稿: 47 参加年月日: 12/12/05 最新の投稿
Hey,

strange..I have the same problem.
When I visit the public site my li elements never get the selected class. When I login , everything is fine ?!?

	#foreach ($nav_item in $nav_items)	
			#if ($nav_item.isSelected())
				<li class="selected">
			#else
				</li>
  • #end


  • Any help?
    10年前 に Michal Sima によって更新されました。

    RE: Problems detecting a selected nav item in velocity template

    New Member 投稿: 24 参加年月日: 13/02/27 最新の投稿
    Did you solve it?
    10年前 に James charley によって更新されました。

    RE: Problems detecting a selected nav item in velocity template

    Junior Member 投稿: 44 参加年月日: 13/06/12 最新の投稿
    Any one solved the above issue ?
    10年前 に Aldi Tirane によって更新されました。

    RE: Problems detecting a selected nav item in velocity template

    Junior Member 投稿: 25 参加年月日: 12/10/23 最新の投稿
    Hello to everyone.
    Did anybody solve this issue?

    Thanks.

    Mason Stein:
    Hey,

    strange..I have the same problem.
    When I visit the public site my li elements never get the selected class. When I login , everything is fine ?!?

    	#foreach ($nav_item in $nav_items)	
    			#if ($nav_item.isSelected())
    				<li class="selected">
    			#else
    				</li>
  • #end


  • Any help?
    10年前 に Laxman Rana によって更新されました。

    RE: Problems detecting a selected nav item in velocity template

    New Member 投稿: 23 参加年月日: 13/07/15 最新の投稿
    Hi,

    Try with this code

    
    <nav class="$nav_css_class" id="nav_menu">
    <ul class="nav">
    #foreach ($nav_item in $nav_items)
    #if ($nav_item.isSelected())
    <li class="selected active">
    #else
    </li><li>
    #end
    </li></ul>
    </nav>


    Thanks,
    Laxman Rana
    Surekha Technologies
    www.surekhatech.com
    10年前 に Aldi Tirane によって更新されました。

    RE: Problems detecting a selected nav item in velocity template

    Junior Member 投稿: 25 参加年月日: 12/10/23 最新の投稿
    The problem is that $nav_item.isSelected() return always false.

    I found why this happens. I have included in header.vm the sign-in portlet with the following code:

    
    #set ($locPortletId = "58")
    $velocityPortletPreferences.setValue("portlet-setup-show-borders","false")		
    #set($locRenderedPortletContent = $theme.runtime($locPortletId, "", $velocityPortletPreferences.toString()))
    $locRenderedPortletContent
    $velocityPortletPreferences.reset()
    


    If i remove this code in the header the $nav_item.isSelected() behaves normally returning true for the page where the user is in.

    I don't know why this happens, maybe someone can give a more detailed explanation.

    Thanks, Aldi.
    thumbnail
    10年前 に Puneet Malode によって更新されました。

    RE: Problems detecting a selected nav item in velocity template

    New Member 投稿: 17 参加年月日: 12/07/20 最新の投稿
    Hi,
    I have created the portlet to access Navigation. But I am not able to get the selected NavItem. Please help me to solve this problem.
    Please find the below code for your reference.

    In my Portlet Controller class.

    
    public String getChildPages(RenderRequest request, RenderResponse response, ExtendedModelMap model){
    		
    		
    		
    		try {
    			ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    			List<layout> layouts  = themeDisplay.getLayouts();
    			Layout layout = themeDisplay.getLayout();
    			HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(request);
    			for (Layout lay : layouts) {
    				System.out.println("Is Layout Selected ? "+lay.isSelected(true, lay, lay.getAncestorPlid()));
    				System.out.println("Is Child Selected ? "+lay.isChildSelected(true, lay));
    			}
    			
    			VelocityContext velocityContext = VelocityEngineUtil.getWrappedStandardToolsContext();
    			RequestVars requestVars = new RequestVars(httpServletRequest, themeDisplay, layout.getAncestorPlid(), layout.getAncestorLayoutId(), velocityContext);
    			
    			List<navitem> navItems = NavItem.fromLayouts(requestVars, layouts);
    			
    			for (NavItem navItem : navItems) {
    				System.out.println("NavItem Selected ? "+navItem.isSelected());
    				System.out.println("Is Child Selected ? "+navItem.isChildSelected());
    			}
    			
    			model.put("NavItems", navItems);
    			
    		} catch (PortalException e) {
    			e.printStackTrace();
    		} catch (SystemException e) {
    			e.printStackTrace();
    		}
    		
    		
    		return "LeftNav";
    	}
    </navitem></layout>



    In my JSP

    <ul class="list-group">
    <c:foreach items="${NavItems}" var="navItem">
    	<c:if test="${navItem.hasChildren()}">
    		<c:if test="${navItem.isChildSelected()}">
    			<c:foreach items="${navItem.getChildren()}" var="child1">
    				<c:if test="${child1.isSelected()}">
    					<li class="list-group-item current">
    				
    				<c:if test="${!child1.isSelected()}">
    					</c:if></li><li class="list-group-item">
    				
    						<a href="${child1.getURL() }">
    							${child1.getName() }
    						</a>
    					</li>
    			</c:if></c:foreach>
    		</c:if>
    	</c:if>
    </c:foreach>
    </ul>
    thumbnail
    9年前 に Dominique Ebert によって更新されました。

    RE: Problems detecting a selected nav item in velocity template

    Junior Member 投稿: 29 参加年月日: 13/02/01 最新の投稿
    Hi everybody,
    I know the thread is a little bit old but I found a workaround for the problem someone mentioned in here and I thought it would be better to post it here instead of creating a new thread. I faced the same problem as Aldi Tirane did (see quote). I embedded a Portlet into my theme with the liferay suggested code (see quote again ;) ). But whenever i did that, the isSelected() Function always returned false.

    So I tried to embedd the portlet after the navigation was built and that worked. So I came up with this workaround, maybe its useful to somebody with the same issue:

    - My navigation code was stored in the navigation.vm so I parsed the content of the navigation into a variable:

    
    #set($navigationPath = "$full_templates_path/navigation.vm")
    #set ($navigationParsed="#parse($navigationPath )")
    


    This made sure the navigation had been created before I embedded the portlet. Afterwards I embedded the portlet as suggested in the quote. Afterwards I just printed the content of the variable where I wanted the navigation to appear.

    That worked fine for me, I hope this may be useful to somebody.

    Last but not least - does anybody know why this problem occurs in the first place, or wether it has been resolved after 6.1GA2?

    Regards

    Aldi Tirane:
    The problem is that $nav_item.isSelected() return always false.

    I found why this happens. I have included in header.vm the sign-in portlet with the following code:

    
    #set ($locPortletId = "58")
    $velocityPortletPreferences.setValue("portlet-setup-show-borders","false")		
    #set($locRenderedPortletContent = $theme.runtime($locPortletId, "", $velocityPortletPreferences.toString()))
    $locRenderedPortletContent
    $velocityPortletPreferences.reset()
    


    If i remove this code in the header the $nav_item.isSelected() behaves normally returning true for the page where the user is in.

    I don't know why this happens, maybe someone can give a more detailed explanation.

    Thanks, Aldi.