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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:16:55+00:00 2026-05-24T09:16:55+00:00

My problem is that one of my ViewScoped bean is created several time within

  • 0

My problem is that one of my ViewScoped bean is created several time within the same view. The constructor of ViewScopedBean is created every time I select a node in the tree.

<h:form>
    <p:tree value="#{treeBean.root}" var="node"  
        selectionMode="single" selection="#{viewScopedBean.selectedNode}">  
        <p:ajax event="select" update="selectedNode, treeBeanUpdate, otherBeanUpdate, panel" listener="#{treeBean.onNodeSelect}" /> 
        <p:treeNode>  
            <h:outputText value="#{node}" />  
        </p:treeNode>  
    </p:tree>  
    Selected Node: <h:outputText value="#{viewScopedBean.selectedNode}" id="selectedNode"/><br/>
    Current TreeBean: <h:outputText value="#{treeBean}" id="treeBeanUpdate"/><br/>
    Current OtherBean: <h:outputText value="#{viewScopedBean}" id="otherBeanUpdate"/><br/>
    <p:outputPanel id="panel">
        <ag:profileComponent managedBean="#{viewScopedBean.profileBean}"/>
    </p:outputPanel>
</h:form>

If I remove this part (reference to a composite component), the constructor of ViewScopedBean is not called:

    <p:outputPanel id="panel">
        <ag:profileComponent managedBean="#{viewScopedBean.profileBean}"/>
    </p:outputPanel>

All the beans used are set as @ViewScoped.

@ManagedBean
@ViewScoped
public class ViewScopedBean implements Serializable {

    private TreeNode selectedNode;
    private ProfileBean profileBean;

    public ViewScopedBean() {
        System.out.println("Constructor of ViewScopedBean " + this);
    }

    @PostConstruct
    public void init() {
        System.out.println("ViewScoped init" + this);
        profileBean = new ProfileBean();
    }
}

Is it the correct behaviour? If not what can cause it?

Update: I tried to use an empty composite, and I have the same problem.

<?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:f="http://java.sun.com/jsf/core"      
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:composite="http://java.sun.com/jsf/composite">

      <composite:interface>
            <composite:attribute name="managedBean" required="true"/>
      </composite:interface>

      <composite:implementation>
      </composite:implementation>

</html>

But if I made the managedBean not required, that’s fine.

Another thing I don’t get is when the constructor is called, it seems that the object created is not used.

Initiating the view (console output):

Constructor of ViewScopedBean xxx.bean.ViewScopedBean@4e1d2b8e

2 clicks on the tree:

Constructor of ViewScopedBean xxx.bean.ViewScopedBean@4eb64f2e
Constructor of ViewScopedBean xxx.bean.ViewScopedBean@66863941

Then I open the debug window <ui:debug/>, the viewScopedBean is set to xxx.bean.ViewScopedBean@4e1d2b8e

  • 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-24T09:16:56+00:00Added an answer on May 24, 2026 at 9:16 am

    The view scoped bean will be recreated on every request from/to the same view, when you use JSTL tags like <c:if>, <c:forEach> and so on in the view, or when you bind a JSF component as a property of the view scoped bean using binding attribute. That’s apparently what’s happening in your composite component.

    You need to rewrite your composite component as such that it does not utilize any JSTL tags. Binding some JSF component as a property of the bean can also be avoided in many ways, but if that is really not avoidable, then disabling the partial state saving in web.xml should work in most of the cases:

    <context-param>
        <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
        <param-value>false</param-value>
    </context-param>
    

    If that doesn’t work for you, then you really have to share your composite component implementation code with us so that we can point out the caveats and propose the right approaches.

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

Sidebar

Related Questions

I have an InfoPath form with several fields on, the problem is that one
i have created one image but problem is that when i save image from
We link our app with numerous different static libs, the problem is that one
I have been optimizing my website but the one problem that stands in my
I'm almost finished with my program, but I have one problem that I can't
Modifying CKEditor 3.6.2 is not easy, but I tried hard . One problem that
My problem is one that you would think is quite common, but I haven't
I'm stuck on one small problem that stop development for a feature I'm trying
I've got one head scratcher of a problem that I can't seem to find
I am trying to include different pages on one page. However the problem that

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.