NutzCN Logo
问答 jsp页面如何替换下面的表达式
发布于 2707天前 作者 qq_cdeebfe2 2227 次浏览 复制 上一个帖子 下一个帖子
标签:

<%
var secondMenus=@shiro.getPrincipalProperty('secondMenus');
for(firstMenu in @shiro.getPrincipalProperty('firstMenus')){

        %>
26 回复

shiro有标签库

不好意思,查询了一下 ,还是看不明白怎么用shiro有标签库遍历权限菜单

想起来了, 不需要标签库.

那是nutzwk的代码吧? shiro是req的是一个attr, 取就是了

我现在用el表达式写的,firstMenus不显示出来 ,我把第二层作为和第三层作为menu ,我下面该怎么修改一下就能遍历出来了?

<div class="sidebar-collapse">
                <ul class="nav" id="side-menu">
                    <c:forEach items="${shiro.getPrincipalProperty('firstMenus')}" var="firstMenus" >
                        <c:forEach items="${shiro.getPrincipalProperty('secondMenus')}" var="secondMenus" >

                    <li>     <c:if test="${secondMenus.key ==firstMenus.path }">
                                <c:forEach items="${secondMenus.value}" var="secondMenu" >


                                <a href="#">
                                    <i class="fa fa-circle-thin"></i>
                                    <span class="nav-label">${secondMenu.name}</span>
                                    <span class="fa arrow"></span>
                                </a>
                                </c:forEach>
                               </c:if>
                        <ul class="nav nav-second-level">

                                <c:if test="${secondMenus.key == secondMenu.path}">
                                    <c:forEach items="${secondMenu.value}" var="thMenu" >

                                            <li>
                                                <a class="J_menuItem" href="${thMenu.href}" data-index="0">${thMenu.name}</a>
                                            </li>

                                    </c:forEach>

                               </c:if>

                        </ul>
                    </li>
                        </c:forEach>
                            </c:forEach>



                </ul>
            </div>

是firstMenus和secondMenus都没有?

都有,firstMenus 是系统,不想显示,只想显示是secondMenus 系统管理,和系统管理下面的几个菜单,现在是系统管理能显示出来,系统管理下面的几个菜单不知道怎么用条件判断来显示

都显示嘛,然后js/css隐藏掉

@wendal 下面这种语法,如果在jsp里面该怎么写啊?
for(firstMenu in @shiro.getPrincipalProperty('firstMenus')){
}

你自己不是写了吗?

<c:forEach items="${shiro.getPrincipalProperty('firstMenus')}" var="firstMenus" >

这么写遍历这个菜单总是遍历不出来~ 哭

secondMenus.get(firstMenu.path) 这种写法 ,在jsp里我可以这么写吗 secondMenus【firstMenu.path】

@wendal 为什么这么写 不行额?
<c:forEach items="${shiro.getPrincipalProperty('firstMenus')}" var="firstMenus" >
<c:forEach items="${shiro.getPrincipalProperty('secondMenus')}" var="secondMenus" >
<c:forEach items="${secondMenus[firstMenu.path]}" var="secondMenu" >

先确认一下shiro.getPrincipalProperty('firstMenus') 是否有值

这么写${shiro.getPrincipalProperty('firstMenus')}是有值~
这么写${secondMenus[firstMenu.path]} 没有值

这么写${secondMenus[firstMenus.path]} 没有值
抛下面的异常信息
Caused by: javax.el.PropertyNotFoundException: Property '0001' not found on type java.util.HashMap$Node

那map实现不了我想要的,如果我想要nutzwk这样,secondMenus.get(secondMenu.path) ,通过path获取它下面的所有菜单,该怎么写啊?在jsp里面我这么写secondMenus.get(secondMenu.path) 不认。

<% for(secondMenu in @secondMenus.get(firstMenu.path)){ %>

<a href="<% if(!isEmpty(secondMenu.href)){ %><%if(@string.startWith(secondMenu.href,'/')){%>${base}${secondMenu.href!}<%}else{%>${secondMenu.href!}<%}%> <% }else{ %>javascript:;<% } %>" <%if(@string.startWith(secondMenu.target,'_')){%>target="${secondMenu.target!}"<%}else{%>${secondMenu.target!}<%}%>>
<% if(!isEmpty(@secondMenus.get(secondMenu.path))){ %><%}%>
<%if(lang=="zh_CN"){%>${secondMenu.name}<%}else{%>${secondMenu.aliasName}<%}%>

<% if(!isEmpty(@secondMenus.get(secondMenu.path))){ %>

<% for(thMenu in @secondMenus.get(secondMenu.path)){ %>

<a <% if(!isEmpty(thMenu.href)){ %>href="<%if(@string.startWith(thMenu.href,'/')){%>${base}${thMenu.href!}<%}else{%>${thMenu.href!}<%}%>" <% }else{ %>href="javascript:;"<% } %> <%if(@string.startWith(thMenu.target,'_')){%>target="${thMenu.target!}"<%}else{%>${thMenu.target!}<%}%>>
<%if(lang=="zh_CN"){%>${thMenu.name}<%}else{%>${thMenu.aliasName}<%}%>

<% }%>
<%}%>
<% } %>
<% } %>

el表达式好像不能这么写 <c:forEach items="${secondMenus.get(firstMenu.path)}" var="secondMenu" >

<c:forEach items="${secondMenus.get(firstMenu.path)}" var="secondMenu" > 这么写的话抛下面的异常:
Caused by: javax.el.MethodNotFoundException: Method not found: class java.util.HashMap$Node.get(null)

firstMenu.value.path

PS: 回复按钮旁边还有个"插入代码或日志片段"的按钮!!!!!!!!!!!!!!!!!!!

这么写<c:forEach items="${secondMenus.value.[firstMenus.path]}" var="secondMenu" > 对吗,怎么还是抛异常呢

<c:forEach items="${shiro.getPrincipalProperty('firstMenus')}" var="firstMenus" >
                        <c:forEach items="${shiro.getPrincipalProperty('secondMenus')}" var="secondMenus" >

                    <li>
                            <c:forEach items="${secondMenus.value.[firstMenus.path]}" var="secondMenu" >

                                        <a href="#">
                                            <i class="fa fa-circle-thin"></i>
                                            <span class="nav-label">${secondMenu.name}</span>
                                            <span class="fa arrow"></span>
                                        </a>


                        <ul class="nav nav-second-level">



                        </ul>
                    </li>
                        </c:forEach>
                            </c:forEach>
                    </c:forEach>

secondMenus的是啥? Map<String, List<Menu>> 吗?

${secondMenus[firstMenus.value.path]}

secondMenus是

Map<String, List<Menu>> secondMenus = new HashMap<>();

${secondMenus[firstMenus.value.path]} 抛下面的异常信息

Caused by: javax.el.PropertyNotFoundException: Property '0001' not found on type java.util.HashMap$Node

map使用[ ...]这个运算符[ ...]这个里面是变量 ,而不是值?

所以第二层foreach是多余的,删掉. 应该直接取

<c:forEach items="${shiro.getPrincipalProperty('secondMenus')}[firstMenus.value.path]}" var="secondMenu" >

@wendal 遍历出来了~~谢谢 谢谢!! 辛苦

添加回复
请先登陆
回到顶部