我正在尝试在JSF中实现我能够做到的菜单。
menucontents.jsp:
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=UTF-8" />
<title>MyFaces - the free JSF Implementation</title>
<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/pages/css/basic.css" />
</head>
<body>
<f:view>
<f:loadBundle basename="com.cpc.resources.menu" var="menu"/>
<t:div id="hNav_outer">
<t:panelNavigation2 id="nav1" layout="list" itemClass="off" activeItemClass="on" openItemClass="on"
renderAll="true">
<t:commandNavigation2 value="#{menu['menu_Home']}" style="padding-left: 0px;">
<t:commandNavigation2>
<f:verbatim>› </f:verbatim>
<t:outputText value="#{menu['menu_Home']}"/>
</t:commandNavigation2>
</t:commandNavigation2>
<t:commandNavigation2 value="#{menu['menu_admin']}" style="padding-left: 150px;">
<t:commandNavigation2>
<f:verbatim>› </f:verbatim>
<t:outputText value="#{menu['menu_admin_change_password']}"/>
</t:commandNavigation2>
<t:commandNavigation2>
<f:verbatim>› </f:verbatim>
<t:outputText value="#{menu['menu_admin_forgot_password']}"/>
</t:commandNavigation2>
</t:commandNavigation2>
</t:panelNavigation2>
</t:div>
</f:view>
</body>
</html>
引入了menu.jsp:
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=UTF-8" />
<title>MyFaces - the free JSF Implementation</title>
<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/pages/css/basic.css" />
</head>
<body>
<f:view>
<f:subview id="headerinclude1">
<jsp:include page="menucontents.jsp" />
</f:subview>
</f:view>
</body>
</html>
我尝试了各种组合,即删除HTML / BODY / f:view标签,但似乎没有任何工作我知道某处我做错了不能检查它。任何帮助将不胜感激。
此外,代码的第一部分作为单个文件执行时效果非常好,唯一的问题是当我将其包含在另一个JSP中时,菜单不会显示。
答案 0 :(得分:1)
<f:subview>
必须包含在包含文件中,而不是在父文件中。将<f:view>
文件中的menucontents.jsp
替换为<f:subview>
,然后从<f:subview>
中删除menu.jsp
。
总结:
menu.jsp
<f:view>
<jsp:include page="menucontents.jsp" />
</f:view>
menucontents.jsp
<f:subview id="menucontents">
<f:loadBundle basename="com.cpc.resources.menu" var="menu"/>
...
</f:subview>
(请注意,包含文件应不有<f:view>
,您也不需要围绕它的HTML头部/主体,这只会产生{{3 HTML)