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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:04:12+00:00 2026-05-28T06:04:12+00:00

I have put my problem case below, which simplifies a real world problem I

  • 0

I have put my problem case below, which simplifies a real world problem I am having. By changing the Bean to @SessionScoped I can solve this, but that is really undesirable. As is @ViewScoped. I think it should work in @RequestScoped. My questions are:

  • Why does JSF need access to #{simpleBean.outerStrings} to invoke the #{simpleBean.processInnerClick()} listener (outerStrings will have died in the previous request)
  • What is the best pattern for solving this?

Happy to edit to make clearer – just let me know.

Bean class

import javax.enterprise.context.RequestScoped;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@Named
@RequestScoped
public class SimpleBean implements Serializable {

    private List<String> topLevelStrings = 
               Arrays.asList("TopLevel1", "TopLevel2");

    private List<String> outerStrings;

    private List<String> innerStrings;

    public void processOuterClick() {
        System.err.println("processOuterClick()");
        outerStrings = Arrays.asList("Outer1", "Outer2", "Outer3");
    }

    public void processInnerClick() {
        System.err.println("processInnerClick()");
        innerStrings = Arrays.asList("InnerA", "InnerB", "InnerC");
    }

    public List<String> getOuterStrings() {
        return outerStrings;
    }

    public List<String> getInnerStrings() {
        return innerStrings;
    }

    public List<String> getTopLevelStrings() {
        return topLevelStrings;
    }

}

XHTML

<h:form>
<ui:repeat var="toplevel" value="#{simpleBean.topLevelStrings}"
           id="toplevel_id">
<h:commandLink id="toplevel_command">
#{toplevel} <br/>
<f:ajax render="outerlevel_panel" 
        listener="#{simpleBean.processOuterClick()}"/>
</h:commandLink>
<h:panelGroup id="outerlevel_panel">
<ui:repeat var="outerLevel" value="#{simpleBean.outerStrings}" 
    id="outerlevel_id">
<h:commandLink id="outerlevel_command">
#{outerLevel} <br/> 
<f:ajax listener="#{simpleBean.processInnerClick()}" render="innerlevel_panel"/>                   
</h:commandLink>                            
<h:panelGroup id="innerlevel_panel">
<ui:repeat var="innerLevel" value="#{simpleBean.innerStrings}" 
           id="innerlevel_id">
<h:commandLink id="innerlevel_command">
#{innerLevel} <br/>        
</h:commandLink>
</ui:repeat>
</h:panelGroup>
</ui:repeat>
</h:panelGroup>         
</ui:repeat>
</h:form>

Basically:

  • The #{simpleBean.processOuterClick()} listener fires ok and the #{outerLevel} command links render
  • But when I click on the #{outerLevel} command Link the #{simpleBean.processInnerClick()} listener is never fired
  • 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-28T06:04:13+00:00Added an answer on May 28, 2026 at 6:04 am

    The request scope is the wrong scope for this particular requirement. A request scoped bean is garbaged by end of the response and a new one will be created in the subsequent request with all of its properties set to default. In JSF2 terms, you really need the view scope. The session scope is indeed too broad and much worse for this requirement than the request scope (when an enduser opens the same page in multiple windows/tabs, they will share physically the one and same bean, resulting in unintuitive per-view behaviour when the enduser switches between views after interactions).

    All you need to do to fix your particular problem is to use @ManagedBean @ViewScoped:

    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.ViewScoped;
    
    @ManagedBean
    @ViewScoped
    public class SimpleBean implements Serializable {
        // ...
    }
    

    As you seem to prefer CDI management over JSF management for some reason, the CDI alternative to @ViewScoped is @ConversationScoped.

    import javax.enterprise.context.Conversation;
    import javax.enterprise.context.ConversationScoped;
    import javax.inject.Named;
    
    @Named
    @ConversationScoped
    public class SimpleBean implements Serializable {
    
        @Inject
        private Conversation conversation;
    
        @PostConstruct
        public void init() {
            conversation.begin();
        }
    
        public String navigateToOtherPage() {
            conversation.end();
            return "otherPage?faces-redirect=true";
        }
    
        // ...
    }
    

    You only have to manage the begin and end of the conversation yourself.

    See also:

    • commandButton/commandLink/ajax action/listener method not invoked or input value not updated
    • Communication in JSF2 – Managed bean scopes
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have put together a little test case to demonstrate my problem: package P1;
In my login script I have put a checkbox that people can check if
I have a JSF2 (GlassFish 3.0) application which security constraints defined (example below). My
I have a problem that I have been trying to solve for a couple
Possible Duplicate: Paypal Checkout Express empty cart problem i have an issue with paypal
I have an existing PDF and I can use FdFWriter to input to text
I have put an UltraGrid on a WinForms user control. I have tweaked some
I have an xml file right now which has a TableLayout within a LinearLayout.
I have this problem. I read with BufferedReader text from one system file, this
I have a price of js code, which has been troubling me since last

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.