I’m using JSF-2.0 and I’m trying to include a jsp as a header for my current jsp.But all i want is the included jsp should be altered based on the login credentials.
More clearly…depending on the person logging in to my application, the header menu (included jsp) should be different.I’ve tried implementing in the below way but it did not work..any help would be appreciated
<html>
<head></head>
<body>
<%
String menuHeader = (String) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("menuAssigned");
if (menuHeader.equals("XX")){ %>
<f:view> <jsp:include page="XHeader.jsp" /> </f:view>
<% }else if(menuHeader.equals("YY")){ %>
<f:view> <jsp:include page="YHeader.jsp" />
<%}%>
---
</f:view>
</body>
</html>
Don’t use Scriptlets. Ever.
Your
menuAssignedvariable is just available in EL by#{menuAssigned}. I suggest to align yourmenuAssignedvariable value with the JSP include filename. Then you can just useImagine that
menuAssignedisXX, then this will includeXXHeader.jsp.Unrelated to the concrete problem, why are you using legacy JSPs while you’re apparently already on JSF 2.0 which comes along with JSP’s awesome successor Facelets (XHTML)?