Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
E S
Problems detecting a selected nav item in velocity template
21 de Julho de 2010 06:21
Resposta

E S

Ranking: Junior Member

Mensagens: 38

Data de entrada: 21 de Abril de 2010

Mensagens recentes

I am having a problem in my navigation.vm template. Here is the code for the site's navigation:

 1
 2<ul>
 3    #foreach ($nav_item in $nav_items)
 4        #if ($nav_item.isSelected())
 5            #set ($nav_item_class = "selected")
 6            <b>Selected!</b>
 7        #else
 8            #set ($nav_item_class = "")
 9        #end
10
11        #if ($nav_item.getName() != "Home")
12            <li class="$nav_item_class">
13                <a href="$nav_item.getURL()" $nav_item.getTarget()><span>$nav_item.getName()</span></a>
14            </li>
15        #end
16    #end
17</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?
Robert Kornmesser
RE: Problems detecting a selected nav item in velocity template
18 de Janeiro de 2012 03:59
Resposta

Robert Kornmesser

Ranking: Junior Member

Mensagens: 39

Data de entrada: 3 de Novembro de 2011

Mensagens recentes

Same problem here!
In portal_normal.vm, i include navigation 2 times. First time isSelected(() works as desired. second time not.
WHY?
Anônimo
RE: Problems detecting a selected nav item in velocity template
24 de Julho de 2012 09:33
Resposta

Anônimo

you need to add $nav_item.siblings

to

1#foreach($nav_item in $nav_item.siblings)
2
3$nav_item
4#end
Mason Stein
RE: Problems detecting a selected nav item in velocity template
31 de Dezembro de 2012 08:08
Resposta

Mason Stein

Ranking: Junior Member

Mensagens: 47

Data de entrada: 5 de Dezembro de 2012

Mensagens recentes

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 ?!?

1    #foreach ($nav_item in $nav_items)   
2            #if ($nav_item.isSelected())
3                <li class="selected">
4            #else
5                <li>
6            #end


Any help?
Michal Sima
RE: Problems detecting a selected nav item in velocity template
29 de Maio de 2013 09:01
Resposta

Michal Sima

Ranking: New Member

Mensagens: 23

Data de entrada: 27 de Fevereiro de 2013

Mensagens recentes

Did you solve it?
James charley
RE: Problems detecting a selected nav item in velocity template
20 de Junho de 2013 04:25
Resposta

James charley

Ranking: Junior Member

Mensagens: 44

Data de entrada: 11 de Junho de 2013

Mensagens recentes

Any one solved the above issue ?
Aldi Tirane
RE: Problems detecting a selected nav item in velocity template
16 de Julho de 2013 00:00
Resposta

Aldi Tirane

Ranking: Junior Member

Mensagens: 25

Data de entrada: 23 de Outubro de 2012

Mensagens recentes

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 ?!?

1    #foreach ($nav_item in $nav_items)   
2            #if ($nav_item.isSelected())
3                <li class="selected">
4            #else
5                <li>
6            #end


Any help?
Laxman Rana
RE: Problems detecting a selected nav item in velocity template
16 de Julho de 2013 00:26
Resposta

Laxman Rana

Ranking: New Member

Mensagens: 23

Data de entrada: 14 de Julho de 2013

Mensagens recentes

Hi,

Try with this code

 1
 2<nav class="$nav_css_class" id="nav_menu">
 3<ul class="nav">
 4#foreach ($nav_item in $nav_items)
 5#if ($nav_item.isSelected())
 6<li class="selected active">
 7#else
 8<li>
 9#end
10</ul>
11</nav>


Thanks,
Laxman Rana
Surekha Technologies
www.surekhatech.com
Aldi Tirane
RE: Problems detecting a selected nav item in velocity template
16 de Julho de 2013 00:38
Resposta

Aldi Tirane

Ranking: Junior Member

Mensagens: 25

Data de entrada: 23 de Outubro de 2012

Mensagens recentes

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:

1
2#set ($locPortletId = "58")
3$velocityPortletPreferences.setValue("portlet-setup-show-borders","false")       
4#set($locRenderedPortletContent = $theme.runtime($locPortletId, "", $velocityPortletPreferences.toString()))
5$locRenderedPortletContent
6$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.
Puneet Malode
RE: Problems detecting a selected nav item in velocity template
30 de Março de 2014 23:37
Resposta

Puneet Malode

Ranking: New Member

Mensagens: 17

Data de entrada: 20 de Julho de 2012

Mensagens recentes

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.

 1
 2public String getChildPages(RenderRequest request, RenderResponse response, ExtendedModelMap model){
 3       
 4       
 5       
 6        try {
 7            ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
 8            List<Layout> layouts  = themeDisplay.getLayouts();
 9            Layout layout = themeDisplay.getLayout();
10            HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(request);
11            for (Layout lay : layouts) {
12                System.out.println("Is Layout Selected ? "+lay.isSelected(true, lay, lay.getAncestorPlid()));
13                System.out.println("Is Child Selected ? "+lay.isChildSelected(true, lay));
14            }
15            
16            VelocityContext velocityContext = VelocityEngineUtil.getWrappedStandardToolsContext();
17            RequestVars requestVars = new RequestVars(httpServletRequest, themeDisplay, layout.getAncestorPlid(), layout.getAncestorLayoutId(), velocityContext);
18            
19            List<NavItem> navItems = NavItem.fromLayouts(requestVars, layouts);
20            
21            for (NavItem navItem : navItems) {
22                System.out.println("NavItem Selected ? "+navItem.isSelected());
23                System.out.println("Is Child Selected ? "+navItem.isChildSelected());
24            }
25            
26            model.put("NavItems", navItems);
27            
28        } catch (PortalException e) {
29            e.printStackTrace();
30        } catch (SystemException e) {
31            e.printStackTrace();
32        }
33       
34       
35        return "LeftNav";
36    }



In my JSP

 1<ul class="list-group">
 2<c:forEach items="${NavItems}" var="navItem" >
 3    <c:if test="${navItem.hasChildren()}">
 4        <c:if test="${navItem.isChildSelected()}">
 5            <c:forEach items="${navItem.getChildren()}" var="child1">
 6                <c:if test="${child1.isSelected()}">
 7                    <li    class="list-group-item current">
 8                </c:if>
 9                <c:if test="${!child1.isSelected()}">
10                    <li    class="list-group-item">
11                </c:if>
12                        <a href="${child1.getURL() }">
13                            ${child1.getName() }
14                        </a>
15                    </li>
16            </c:forEach>
17        </c:if>
18    </c:if>
19</c:forEach>
20</ul>
Dominique Ebert
RE: Problems detecting a selected nav item in velocity template
11 de Dezembro de 2014 05:02
Resposta

Dominique Ebert

Ranking: Junior Member

Mensagens: 29

Data de entrada: 1 de Fevereiro de 2013

Mensagens recentes

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:

1
2#set($navigationPath = "$full_templates_path/navigation.vm")
3#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:

1
2#set ($locPortletId = "58")
3$velocityPortletPreferences.setValue("portlet-setup-show-borders","false")       
4#set($locRenderedPortletContent = $theme.runtime($locPortletId, "", $velocityPortletPreferences.toString()))
5$locRenderedPortletContent
6$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.