1

I am trying to implement menus in JSF which I was able to do it.

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>&#8250; </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>&#8250; </f:verbatim>
                    <t:outputText value="#{menu['menu_admin_change_password']}"/>
                </t:commandNavigation2>
                <t:commandNavigation2>
                    <f:verbatim>&#8250; </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>

I have tried various combinations i.e by removing the HTML / BODY / f:view tags but nothing seems to be working I know somewhere I am doing it wrong not able to check it. Any help would be appreciated.

Also, the first part of code when executed as an single file it works very well the only problem is when I include it in another JSP the menus are not getting displayed.

Ameya Thakur
  • 53
  • 2
  • 12

1 Answers1

1

The <f:subview> has to go in the include file, not in the parent file. Replace the <f:view> in menucontents.jsp file by <f:subview> and remove the <f:subview> from the menu.jsp.

Summarized:

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>

(note that the include file should not have a <f:view>, you also don't need a HTML head/body around it, that would only produce invalid HTML)

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks a lot for @BalusC really appreciated your answer I tried the things which you had mentioned and now when I am invoke menu.jsp I get the following "› › › " as an output on the browser – Ameya Thakur Feb 10 '11 at 22:02
  • @BalusC I am still not getting the Desired Output I am getting "› › › " as an output on the browser – Ameya Thakur Feb 10 '11 at 22:07
  • That's a different problem which goes beyond the problem statement in the current question. Your current question is been answered. Just ask a new question :) – BalusC Feb 10 '11 at 22:08
  • @BalusC can you please help me out with the following example I am trying to use – Ameya Thakur Feb 17 '11 at 23:44
  • Sorry, I'm not familiar with those components. There's also too much noise in the code to quickly spot the problem. This will demotivate many users to take a closer look. Try to come up with a compact and minimalistic code snippet which exhibits the whole problem at its own in a nicely formatted [SSCCE](http://sscce.org). By the way, are you really using JSF 1.0/1.1? That's over 5 years old and out of life. Consider upgrading to JSF 1.2 or better 2.0. Or when you're actually already using JSF 1.2, then you can just get rid of all those ugly `` tags ;) – BalusC Feb 18 '11 at 00:32