• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
山高我为峰
博客园    首页    新随笔    联系   管理    订阅  订阅
According to TLD or attribute directive in tag file, attribute sort does not accept any expressions

自定义了一个标签,报错报如下:

According to TLD or attribute directive in tag file, attribute sort does not accept any expressions

意思:根据TLD或tag文件中的属性,属性“sort”不接受任何表达式

 

/*
*自定义了一个菜单标签
*/
public
class MenuTag extends SimpleTagSupport { private PageContext pageContext; private String contextPath; private String charset = "UTF-8"; private String imgPath = "manage/scripts/customMenu/menu/"; private StringBuffer html = new StringBuffer(""); private String shieldMenu = ReadConfigFileUtil.getValue("shieldMenu");// 要的屏蔽菜单名 private String sort; @SuppressWarnings("unchecked") @Override public void doTag() throws JspException, IOException { // 获取用户权限 HttpSession session = pageContext.getSession(); if (session.getAttribute("leftMenuHtml") == null || !String.valueOf(session.getAttribute("leftMenuSort")).equals(sort)) { contextPath = pageContext.getServletContext().getContextPath() + "/"; List<Resource> resources = (List<Resource>) session.getAttribute("userTopLevelMenuList"); List<Resource> subResource = new ArrayList<Resource>(); for (Resource ritem : resources) { if (ritem.getSort().equals(Integer.valueOf(sort))) { subResource.addAll(ritem.getChildrens()); } } html.append("<ul id=\"ulParent\">"); for (Resource r : subResource) { if (!shieldMenu.contains(";" + r.getName() + ";")) { html.append("<li class='liParent'><div class='divParent'>"); html.append("<img class='imgIcon' src='" + contextPath + imgPath + r.getIcon() + "'/>"); html.append("<img class='upOrDownHover' src='" + contextPath + imgPath + "downHover.png'/>"); html.append("<label>" + r.getName() + "</label></div>"); if (r.getChildrens() != null && r.getChildrens().size() > 0) { ArrayList<Resource> resourcess = new ArrayList<Resource>(r.getChildrens()); CommonUtil.getSortResource(resourcess); getChildrenMenu(resourcess, 2, "menu1Name=" + URLEncoder.encode(r.getName(), charset)); } html.append("</li>"); } } html.append("</ul>"); session.setAttribute("leftMenuHtml", html.toString()); session.setAttribute("leftMenuSort", sort); } pageContext.getOut().print((String) session.getAttribute("leftMenuHtml")); } /** * 组合下级菜单 * * @param set * @return * @throws IOException */ private void getChildrenMenu(List<Resource> resources, int level, String parentName) throws IOException { Iterator<Resource> it = resources.iterator(); while (it.hasNext()) { Resource r = it.next(); if (!SystemStatics.MARK_OPERATE.equals(r.getMark()) && !shieldMenu.contains(";" + r.getName() + ";")) { String name = parentName + "&amp;menu" + level + "Name=" + URLEncoder.encode(r.getName(), charset); String url = contextPath + r.getUrl() + "?" + name; html.append("<ul class='ulChild'><li class='liChild'>"); html.append("<div id='" + r.getId() + "' class='divChild'" + " style='padding-left:" + level * 8 + "px' " + "lang='" + r.getMark() + "' checkUrl='" + r.getUrl() + "' url='" + url + "'>"); if (SystemStatics.MARK_LINK.equals(r.getMark())) { html.append("<img class='imgIconSmall circle' src='" + contextPath + imgPath + "circle.png'/>"); } else { html.append("<img class='imgIconSmall plus' src='" + contextPath + imgPath + "plus.png'/>"); } html.append("<label>" + r.getName() + "</label></div>"); if (r.getChildrens() != null && r.getChildrens().size() > 0) { ArrayList<Resource> resourcess = new ArrayList<Resource>(r.getChildrens()); CommonUtil.getSortResource(resourcess); getChildrenMenu(resourcess, level + 1, name); } html.append("</li></ul>"); } } } @Override public void setJspContext(JspContext pc) { pageContext = (PageContext) pc; } public String getSort() { return sort; } public void setSort(String sort) { this.sort = sort; } }

在tld标签库文件中添加该标签:

  <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd">
    <description></description>
    <display-name>"Privilege Tags"</display-name>
    <tlib-version>1.0</tlib-version>
    <short-name>p</short-name>
    <tag>
        <description><![CDATA[menu tag]]></description>
        <name>menu</name>
        <tag-class>com.vrv.paw.tag.MenuTag</tag-class>
        <body-content>empty</body-content>
        <attribute>
            <name>sort</name>          
        </attribute>
    </tag>
</taglib>

错误原因就是:

理论:

 

posted on 2015-11-06 09:37  山高我为峰  阅读(372)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3