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 8380859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:33:51+00:00 2026-06-09T16:33:51+00:00

I know how to request object while processing a bean method: @ManagedBean public class

  • 0

I know how to request object while processing a bean method:

@ManagedBean        
public class HomeAction {
    ....
    public String getHtmlFormattedCookiesInfo(){
        FacesContext facesCtx = FacesContext.getCurrentInstance();
        ExternalContext extCtx = facesCtx.getExternalContext();
        HttpServletRequest req = (HttpServletRequest) extCtx.getRequest();
        ....
        // now do something with the req object such as read cookie
        //    or pass req object to another another function 
        //    that knows nothing about JSF
        ....
        }
    }
}

But, I don’t like putting Faces specific code in my bean object.

Is there a way to pass the request using DI and the faces-config.xml?

Question number 9337433 starts to answer it when you want to pass something that is on the request object. But, I want the entire request object.

  • 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-09T16:33:52+00:00Added an answer on June 9, 2026 at 4:33 pm

    The FacesContext is in EL scope available by #{facesContext}.

    So, this should do, provided that the managed bean is itself also request scoped.

    @ManagedProperty("#{facesContext.externalContext.request}")
    private HttpServletRequest request;
    

    However, having javax.servlet imports in your JSF code more than often indicate code smells and that the particular functional requirement can also just be solved the JSF way. As per the comments, you seem to be interested in collecting request cookies. You should be using the non-Servlet-API-specific methods of the ExternalContext class for this. See the javadoc for a complete overview. The cookies are also available by just ExternalContext#getRequestCookieMap():

    Map<String, Object> cookies = externalContext.getRequestCookieMap();
    

    Which is also available by #{cookie} in EL (also here, the managed bean must be request scoped):

    @ManagedProperty("#{cookie.cookieName}")
    private String cookieValue;
    

    Alternatively, you could look at the Faces class of the JSF utility library OmniFaces to save some common boilerplate.

    String cookieValue = Faces.getRequestCookie("cookieName");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that using Dim currUser As String = Request.ServerVariables(LOGON_USER) returns the Domain\Username, but
Possible Duplicate: Servlets: doGet and doPost I know doGet() request is appended to the
I know we can request xml, html as well as text images directly using
I know I can use Request.Browser.IsMobileDevice . But does anyone know how it works,
Is it possible to know that a HTTP request is from Ajax?If yes, how?
Does anyone know why I can't see an HTTP request that results in a
Does anyone know if google geolocation feature/api makes an actual request to server even
I have a cost optimization request that I don't know how if there is
I know you can do this <%= Request.Form[0] %> But how do you do
I would like to know how to send a post request in curl and

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.