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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:21:44+00:00 2026-05-12T05:21:44+00:00

Say I have a JSF backing bean, request scope, that has a List as

  • 0

Say I have a JSF backing bean, request scope, that has a List as a member.
In the backing bean, I have a method that is bound to a button on the page.

When the button is first pressed, the method uses an EJB to populate the list.
Upon subsequent presses of the button, I do not want the method to call the DB.

So, I added a check:

if(list == null || list.size() == 0)
   //populate the list

Otherwise, the list will already be populated, so no DB call necessary.
Is this satisfactory for a caching mechanism?

  • 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-05-12T05:21:44+00:00Added an answer on May 12, 2026 at 5:21 am

    Because the bean is request scope, its members will only exist for the lifetime of a single request. So, the data will be fetched every time a page is requested.

    One thing you could do would be have the cached data in a different scope (such as session or application).

      <managed-bean>
        <managed-bean-name>expensiveBean</managed-bean-name>
        <managed-bean-class>lifetime.ExpensiveBean</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
      </managed-bean>
      <managed-bean>
        <managed-bean-name>requestBean</managed-bean-name>
        <managed-bean-class>lifetime.RequestBean</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
        <managed-property>
          <property-name>cachedAsset</property-name>
          <property-class>lifetime.ExpensiveBean</property-class>
          <value>#{expensiveBean}</value>
        </managed-property>
      </managed-bean>
    

    Sample code:

    public class RequestBean {
    
      private ExpensiveBean cachedAsset;
    
      public ExpensiveBean getCachedAsset() {
        return cachedAsset;
      }
    
      public void setCachedAsset(ExpensiveBean cachedAsset) {
        this.cachedAsset = cachedAsset;
      }
    
    }
    

    That way, you could easily reference the data from a request scope bean while keeping request-level artifacts separate.

    Some frameworks add support for page scope, which keeps data tied to the lifetime of the view. That may be another option, depending on your needs.

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

Sidebar

Ask A Question

Stats

  • Questions 545k
  • Answers 545k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • added an answer Well, start off by thinking of which bits of data… May 17, 2026 at 9:17 am
  • added an answer For this task it is a good idea to use… May 17, 2026 at 9:15 am
  • added an answer This is exactly how the Skyhook database (built into many… May 17, 2026 at 9:15 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Say I have an ASMX web service, MyService. The service has a method, MyMethod.
Let's say that you have a presentation tier in JSF, and that your business
I have a JSF page. At one point, I have a <h:selectManyCheckbox> that is
Say we have the following method: private MyObject foo = new MyObject(); // and
I have a JSF web client and a Java client that both use the
Let's say that you have the following Facelet ( Using Facelets 1.1.12 ): edit_item.xhtml
Say I have a method like this: public void SaveData() { try { foreach
Let's say have something like: SELECT energy_produced, energy_consumed, timestamp1 AS timestamp FROM ( SELECT
Say I have the following file structure: app/ app.py controllers/ __init__.py project.py plugin.py If
Say you have an application divided into 3-tiers: GUI, business logic, and data access.

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.