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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:40:07+00:00 2026-06-11T12:40:07+00:00

What do you think is the best way to implement a JSF managed bean

  • 0

What do you think is the best way to implement a JSF managed bean concerning session scope versus request scope?
In my case I have a EAR application with a EJB module and a web module. The EJB module provides stateless session beans.
In the Web module now I am using a ManagedBean in sessionScope. This bean injects some of the staeless session ejbs and holds some value objects containing business data which can be used in different pages.

@Named("workflowController")
@SessionScoped
public class WorkflowController {
    private List<ItemCollection> someList;
    private ItemCollection someBusinessData;
    /* Services */
    @EJB
    private MyService myService;

The bean provides a lot of action methods for the frontend and makes use of the stateless session bean.
Is this general good practise? Or should I change my controller to request scope?
I have seen projects where the frontend controller is used only in RequestScoped and injects all the business Data objects as managedProperties which are implemented as ManagedBeans in SessionScope.

In my example I have only one controller in SessionScope holding all business values and providing business methods implemented in stateless ejbs.
In the other case one controller is used in RequestScopde and there are a lot of BusinessValue objects implemented as MangedBeans in SessionScope which are injected into the controller bean.

My question is: Is it bad practice to inject Session EJBs into a SessionScope Managed bean in general?

  • 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-11T12:40:09+00:00Added an answer on June 11, 2026 at 12:40 pm

    If a session scoped managed bean needs to access business logic, then it’s not a bad practice to inject a stateless EJB into it.

    What might be a bad practice is overusing session scoped beans.

    Use a session scoped beans only for things that are truly global for an HTTP session, like details about the currently logged-in user or a shopping cart. Be aware of the fact that session scoped beans might be subject to race conditions whenever the user opens multiple windows or tabs in a browser.

    In a typical web applications with tens to hundreds of pages there should often only be a handful of session scoped beans at most.

    For managed beans that back a single page (called a backing bean), the view scope is very often the most appropriate scope in JSF. Depending on what the page exactly does the request scope might also be appropriate. As a rule of thumb, when data is loaded when the page is initially requested that’s also needed after a post-back, use the view scope. If there is no such data, try if you can get away with the request scope.

    If you need to span multiple pages in a kind of flow, you could opt for passing data via GET parameters if it concerns data that is already persisted and for which you can pass Ids of them around. Otherwise you might wanna look into the conversation scope.

    Unfortunately JSF 2.1 and before don’t natively support the view scope for CDI managed beans, but third party projects like CODI provide an implementation (JSF 2.2 will most likely support the view scope for CDI out of the box).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to think of the best way to implement SerializationInfo GetDouble(string value) but
I was wondering which you think is the best way to implement a "last
I think the best way to express my question is by showing an example:
I'm a little stumped on this one. I think the best way to ask
I'm try to think of the best way to cache a very large collection
The best way I think to explain this is to tell you what my
The best way I can think of to ask this is by example... In
This is the best way I can think of phrasing this question, given this
I'm just wondering what's the best way to implement a threaded conversation like the
What's the best way implement MS SQL full-text search using all the normal things

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.