include a jsp as a header based on a condition inJSF

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>

-------------Problems Reply------------

Don't use Scriptlets. Ever.

Your menuAssigned variable is just available in EL by #{menuAssigned}. I suggest to align your menuAssigned variable value with the JSP include filename. Then you can just use

<jsp:include page="#{menuAssigned}Header.jsp" />

Imagine that menuAssigned is XX, then this will include XXHeader.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)?

Short answer, use EITHER JSP or JSF flow control. Don't mix them too much.

<html>
<head></head>
<body>
<f:view>
<h:panelGroup rendered="#{menuHeader == 'XX'}">
<%@include file=”XHeader.jsp" %>
</h:panelGroup>
<h:panelGroup rendered="#{menuHeader == 'YY'}">
<%@include file=”YHeader.jsp" %>
</h:panelGroup>
</f:view>
</body>
</html>

Perhaps static includes? Again, I've been using facelets with JSF for several years now. Not used to the JSP stuff anymore. Its been a while.

Category:java Views:0 Time:2011-11-06

Related post

  • Include another JSP file 2012-02-02

    I am currently trying to learn JSP. My question is, at present I used to include the header and footer of the page using: <%@include file="includes/header.jsp" %> and <%@include file="includes/footer.jsp" %> But now, I have separated the

  • How to include a Runtime file for @include in JSP 2009-01-27

    To include another file in JSP, we use the @include tag <%@ include file="NameOfFile"%> In my case i want to include a html file whose name will known during the run-time - i,e from Database. How can I do this in JSP? --------------Solutions---

  • Automatically include a JSP in every JSP 2009-08-06

    I would like to simplify my JSP's even further by transparently including them. For instance, this is the line I would like to remove: <%@ include file="/jsp/common/include.jsp"%> The include.jsp file basically declares all the tag libraries I

  • Possible to jsp:include a jsp from another package instead of from WebContent/jsp folder? 2009-12-09

    Due to a design decision, our project contains JSP files that include other JSP files like so: <jsp:include page="/jsp/controls/InputControl.jsp"/> These JSP files exist under the WebContent/jsp folder of the project. Is it possible to move the

  • Including a JSP page with Icefaces/Facelets 2010-04-29

    I have a requirement to allow a user to embed JSP pages into my website...I'm using IceFaces/Facelets to do the navigation menus etc. and would like to include a JSP page using ui:include Is there anyway of doing this (given that the JSP is not valid

  • Include a JSP in Lotus web page 2010-06-14

    is there a way to include a jsp page (what it returns) into a lotus web page ? What I'd need is the equivalent of a <jsp:include url="...."> but to use on the lotus side (a "lotus tag" if that exists) The tag would give an HTML String back and

  • How to Include a JSP in a PHP page 2010-06-24

    I wish to include JSPs include files which contain java code in a PHP template. The two includes in question are a header file, and a footer file. Anyone any experience of doing this? We are considering just doing a HTTP request to grab the resulting

  • Struts2 - Including a jsp according to the bean values 2010-12-11

    I need a sort of page switch on Struts2. Like (on index.jsp) if myBean.String="main" include main.jsp else include welcome.jsp I tried with <s:if> or <c:choose> but looks that they can evalutate only boolean. How can I do it? Cheers -----

  • Including a JSP Page Programatically 2010-12-28

    I need to include a JSP page in a Tag class. I believe the standard way to include a JSP page within another JSP page using API is this: request.getRequestDispatcher("included.jsp").include(request, response); However, I noticed that the included pag

  • How to include a JSP page in a Facelets page? 2011-05-24

    I am using Myfaces 2 on Facelets. I have to include a JSP page in a Facelet page. I tried using <ui:include> but it takes only XHTML pages. I also tried using <c:import> and <f:subview> but nothing worked. Googled a lot but didn't g

  • Including a JSP file from a Java EE Filter 2011-06-08

    I am trying to include a JSP page after the end of a filter. I have the following code: public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException { try { chain.doFilter(request, res

  • how to only :include based on a conditional statement 2011-07-21

    I'm trying to grab Posts and only the comments that belong_to that Post based on a conditional: ie. # Grab all posts but only include comments that have been approved. Post.all(:include => :comments, :conditions => ['comments.approved = ?', tru

  • How do I include a jsp file located "above" the public_html folder 2011-08-05

    First, I'm from a PHP background (which may be evident by this question). This is such a simple task to accomplish in PHP yet I'm absolutely perplexed on how to accomplish this with jsp. This is my folder structure on the server: /home + | +-/user-+

  • While pulling the rows from the SQL server view needs to update a table based on some condition 2010-01-20

    I have a requirement to pull some table(let say table A) data by using a view. In that case based on some condition, I need to update the table A and will return the rows from that table. Please let me know if anybody knows the solution for this... -

  • Is it possible to sort the results of a SELECT query in 2 different ways based on a conditional? 2011-01-26

    The following is invalid syntax but it is what I'm trying to say essentially: SELECT * FROM categories ORDER BY menu_order ASC WHERE parent = '1' || IF parent = '0' ORDER BY id ASC; Is it possible to order the results of a select query differently ba

  • How to set row color based on column condition in asp.net website 2011-10-24

    protected void MyGrid_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Image img = (Image)e.Row.FindControl("Status"); int msgid; int.TryParse(Convert.ToString(DataBinder.Eval(e.Row.DataItem, "M

  • Can I make CakePHP return a suitable status code based on certain conditions? 2009-06-03

    This question is slightly related to my old post http://stackoverflow.com/questions/940326/dealing-with-alias-urls-in-cakephp/ After much thought, I am exploring the option of having a custom 404 script in my Cake App, that is reached when a URL does

  • Python: split a list based on a condition? 2009-06-04

    What's the best way, both aesthetically and from a performance perspective, to split a list of items into multiple lists based on a conditional? The equivalent of: good = [x for x in mylist if x in goodvals] bad = [x for x in mylist if x not in goodv

  • Populating Values For DataGridView from DataBase based on the condition 2009-06-24

    I am creating an application where in I want to display the rows in DataGridView based on the values entered by the user in the textbox. For Eg. If the User enters the BookName in the textbox all the details regarding that book should be displayed in

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.226 (s). 11 q(s)