Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8428705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:07:44+00:00 2026-06-10T05:07:44+00:00

I have a problem with a JSF project. GlassFish Server 3.1.2 Mojarra 2.1.6 I’m

  • 0

I have a problem with a JSF project.

  • GlassFish Server 3.1.2
  • Mojarra 2.1.6

I’m trying to show a table containing the request header fields. Therefor I’ve written this managed bean:

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

@ManagedBean
@RequestScoped
public class RequestHeader extends LinkedHashMap<String, List<String>> {
    private List<String> keys;

    @PostConstruct
    public void init() {
        final HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        keys = Collections.list(request.getHeaderNames());
        for (final String key : keys) {
            final List<String> value = Collections.list(request.getHeaders(key));
            final List<String> oldValue = get(key);
            if (oldValue == null) {
                put(key, value);
            } else {
                oldValue.addAll(value);
            }
        }
    }

    public List<String> keys() {
        return keys;
    }
}

This is my JSF page:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
    <h:head>
        <title>HTTP request headers</title>
    </h:head>
    <h:body>
        <h:dataTable value="#{requestHeader.keys()}" var="k" border="1">
            <f:facet name="header">HTTP request headers</f:facet>
            <h:column>
                <f:facet name="header">Key</f:facet>
                <h:outputText value="#{k}" />
            </h:column>
            <h:column>
                <f:facet name="header">Value</f:facet>
                <!-- This forEach seems to be ignored. -->
                <c:forEach items="#{requestHeader[k]}" var="v">
                    <h:outputText value="#{v}" /><br />
                </c:forEach>
            </h:column>
        </h:dataTable>
    </h:body>
</html>

Instead of having the values in the second column of the table, the cells are empty:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>HTTP request headers</title>
    </head>
    <body>
        <table border="1">
            <thead>
                <tr><th colspan="2" scope="colgroup">HTTP request headers</th></tr>
                <tr>
                    <th scope="col">Key</th>
                    <th scope="col">Value</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>user-agent</td>
                    <td></td>
                </tr>
                <tr>
                    <td>host</td>
                    <td></td>
                </tr>
                <tr>
                    <td>accept</td>
                    <td></td>
                </tr>
                <tr>
                    <td>accept-language</td>
                    <td></td>
                </tr>
                <tr>
                    <td>accept-encoding</td>
                    <td></td>
                </tr>
                <tr>
                    <td>cache-control</td>
                    <td></td>
                </tr>
                <tr>
                    <td>connection</td>
                    <td></td>
                </tr>
            </tbody>
        </table>
    </body>
</html>

I did several tests. <h:outputText value="#{requestHeader[k]}" /> and c:forEach on other lists will work.

Why won’t it work this way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:07:46+00:00Added an answer on June 10, 2026 at 5:07 am

    Taghandlers like JSTL tags runs during view build time, while the UI components like JSF <h:xxx> tags runs during view render time. So they doesn’t run in sync as you’d expect from the coding. In your code, at the moment the <c:forEach> runs, the <h:dataTable> hasn’t run at all and thus its var attribute is not been set and thus #{k} is not available when the <c:forEach> runs and thus it retrieves an empty/non-existent collection.

    You need an UI component instead if you want a nested iteration inside another UI component. One of them is Facelets <ui:repeat>.

    <ui:repeat value="#{requestHeader[k]}" var="v">
        <h:outputText value="#{v}" /><br />
    </ui:repeat>
    

    In case you’re still on JSF 1.x, use Tomahawk’s <t:dataList> instead, or simply another <h:dataTable>.

    See also:

    • JSTL in JSF2 Facelets… makes sense?
    • JSTL c:if doesn't work inside a JSF h:dataTable

    Unrelated to the concrete problem: you don’t need a backing bean here at all. All request headers are already as a Map available by the implicit EL object #{header}.

    All with all, your approach can be simplified as follows, without any backing bean:

    <h:dataTable value="#{header.keySet().toArray()}" var="headerName" border="1">
        <f:facet name="header">HTTP request headers</f:facet>
        <h:column>
            <f:facet name="header">Name</f:facet>
            <h:outputText value="#{headerName}" />
        </h:column>
        <h:column>
            <f:facet name="header">Value</f:facet>
            <ui:repeat value="#{header[headerName]}" var="headerValue">
                <h:outputText value="#{headerValue}" /><br />
            </ui:repeat>
        </h:column>
    </h:dataTable>
    

    See also:

    • Implicit EL objects
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok simple question. I have a JSF application, containing a login page. The problem
I have a problem on my project implemented on JSF 1.2 (MyFaces 1.2.6) and
i have a problem with rendering #{} inside JSF page. I'm using Mojarra 2.1.5
I'm developing a web application using JSF 2.0, NetBeans 6.9.1, GlassFish Server 3.1, mojarra
I have Enterprise Application with EJB3 and JSF on Glassfish server. After running this
I have problem with setting proper charset on my jsf pages. I use MySql
I am working in primefaces 3.3 and jsf 2.0. I have problem in deleting
This is the complete source code: http://www.sendspace.com/file/lwxpyf I have a problem with a JSF
I have some problem's with a simple application in JSF 2.0. I try to
I am new to JSF and have a problem with my simple JSF application.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.