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

  • Home
  • SEARCH
  • 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 7585823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:16:05+00:00 2026-05-30T19:16:05+00:00

I have a very strange problem with a SessionScoped bean in a JSF 2.0

  • 0

I have a very strange problem with a SessionScoped bean in a JSF 2.0 project. Using Netbeans 6.9.1, Glassfish 3 server and PrimeFaces 3 as the JSF component library.

Here is some code:

package com.hia.jsf;

import com.hia.netlabel.jpa.Genre;
import com.hia.netlabel.jpa.Label;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;

@ManagedBean
@SessionScoped
public class LabelDetailJSF implements Serializable{

@ManagedProperty("#{genreLabelListJSF}")
private GenreLabelListJSF genreLabelListJSF;
private List<Genre> DetailLabelGenreList;
private Label DetailLabel;
/** Creates a new instance of LabelDetailJSF */
public LabelDetailJSF() {
}
@PostConstruct
public void init(){
           System.out.print("Running init LabelDetailJSF");
           if(genreLabelListJSF.getSelectedLabel()!=null)
           {
                System.out.print("genreLabelListJSF was not null");
                this.DetailLabelGenreList=genreLabelListJSF.getSelectedLabel().getGenreList();
                this.DetailLabel= (genreLabelListJSF.getSelectedLabel());
           }
           if(this.DetailLabelGenreList==null){
               System.out.println("Bloody thing became null");

           }
}






/**
 * @return the DetailLabel
 */
public Label getDetailLabel() {
    return DetailLabel;
}

/**
 * @param DetailLabel the DetailLabel to set
 */
public void setDetailLabel(Label DetailLabel) {
    System.out.println("Setting Detail Label For LabelDetailJSF to:"+DetailLabel.getLabelName());
    this.DetailLabel = DetailLabel;

}

/**
 * @return the DetailLabelGenreList
 */
public List<Genre> getDetailLabelGenreList() {
    System.out.println("There is:"+this.DetailLabelGenreList.size()+ " Genres available");
    return DetailLabelGenreList;
}

/**
 * @param DetailLabelGenreList the DetailLabelGenreList to set
 */
public void setDetailLabelGenreList(List<Genre> DetailLabelGenreList) {
    System.out.println("Setting the DetailLabelGenre List to have "+DetailLabelGenreList.size());
    this.DetailLabelGenreList = DetailLabelGenreList;
}

/**
 * @return the genreLabelListJSF
 */
public GenreLabelListJSF getGenreLabelListJSF() {
    return genreLabelListJSF;
}

/**
 * @param genreLabelListJSF the genreLabelListJSF to set
 */
public void setGenreLabelListJSF(GenreLabelListJSF genreLabelListJSF) {
    this.genreLabelListJSF = genreLabelListJSF;
}

}

So basically I have injected another sessionscoped bean called GenreLabelListJSF into the LabelDetailJSF. I want to display the DetailLabelGenreList inside a dataTable. Here is the XHTML snippet used to display the datatable

<p:dataTable  id="detailLabelGenreGrid" value="#    {labelDetailJSF.detailLabelGenreList}" var="genre"  paginator="true"  styleClass="text70" rows="2" >
                            <p:column  style="min-width:196px;">
                                 #{genre.genreName}
                            </p:column> 
             </p:dataTable>

When the page loads I initially get the table with some rows in. When I click on the paging buttons that is where the fun starts.

I checked the output from all the System.out statements and found the following when the page loads initially.

INFO: Running init LabelDetailJSF
INFO: genreLabelListJSF was not null
INFO: There is:29 Genres available
INFO: There is:29 Genres available
INFO: There is:29 Genres available
INFO: There is:29 Genres available
INFO: There is:29 Genres available
INFO: There is:29 Genres available

When I click on the page buttons of the datatable I get the following:

INFO: Running init LabelDetailJSF
INFO: Bloody thing became null
SEVERE: javax.el.ELException: /LabelDetail.xhtml @62,165 value="#    {labelDetailJSF.detailLabelGenreList}": java.lang.NullPointerException
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:107)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:190)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:178)
    at javax.faces.component.UIData.getValue(UIData.java:554)
    at org.primefaces.component.datatable.DataTable.getValue(DataTable.java:731)
    at javax.faces.component.UIData.getDataModel(UIData.java:1248)
    at javax.faces.component.UIData.setRowIndex(UIData.java:447)
    at javax.faces.component.UIData.visitTree(UIData.java:1184)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1457)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1457)
    at javax.faces.component.UIForm.visitTree(UIForm.java:333)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1457)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1457)
    at com.sun.faces.application.view.StateManagementStrategyImpl.restoreView(StateManagementStrategyImpl.java:223)
    at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:177)
    at com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:131)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:430)
    at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:143)
    at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:199)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:110)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
    at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
    at com.sun.grizzly.comet.CometEngine.executeServlet(CometEngine.java:473)
    at com.sun.grizzly.comet.CometEngine.handle(CometEngine.java:341)
    at com.sun.grizzly.comet.CometAsyncFilter.doFilter(CometAsyncFilter.java:84)
    at com.sun.grizzly.arp.DefaultAsyncExecutor.invokeFilters(DefaultAsyncExecutor.java:161)
    at com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:137)
    at com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:88)
    at com.sun.grizzly.http.TaskBase.run(TaskBase.java:189)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NullPointerException
    at com.hia.jsf.LabelDetailJSF.getDetailLabelGenreList(LabelDetailJSF.java:72)
    at sun.reflect.GeneratedMethodAccessor951.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:302)
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)
    at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
    at com.sun.el.parser.AstValue.getValue(AstValue.java:116)
    at com.sun.el.parser.AstValue.getValue(AstValue.java:163)
    at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:102)
    ... 48 more

From what I can see it is almost like the bean looses scope and gets recreated all the time. Initially the values are there then when the paging starts the bean looses value. For example I noticed that the @ManagedProperty bean also becomes null when the paging starts. Which is kind of crazy as it is also a session scoped bean.

Still a new hand at JSF so I probably made some noob mistake. Must mention that I did initially create this as a ViewScoped bean by accident, and after changing the bean to SessionScoped I undeployed the application restarted Glassfish and build and deployed it again.

Any ideas?

  • 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-30T19:16:07+00:00Added an answer on May 30, 2026 at 7:16 pm

    You’re using the wrong @SessionScoped annotation.

    If you’ve registered the bean with the JSF @ManagedBean annotation, then you need to import the @SessionScoped from the JSF (javax.faces) package as follows:

    import javax.faces.bean.SessionScoped;
    

    When you incorrectly use a CDI scope on a JSF managed bean, then there is effectively no JSF scope for the JSF managed bean and it falls back to its default @RequestScoped, which creates a new instance in each HTTP request.

    If you’ve registered the bean with the CDI @Named annotation, then you need to import the @SessionScoped from the CDI (javax.enterprise.context) package as follows:

    import javax.enterprise.context.SessionScoped;
    

    When you incorrectly use a JSF scope on a CDI managed bean, then there is effectively no CDI scope for the CDI managed bean and it falls back to its default @Dependent scope, which creates a new instance in each EL expression.

    See also:

    • How to choose the right bean scope?
    • Backing beans (@ManagedBean) or CDI Beans (@Named)?
    • What is the default Managed Bean Scope in a JSF 2 application?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have very strange problem, one of our applications is continually querying server by
I have a very strange problem. Using Gmap3, I place the pin on the
I have this very strange problem while compiling the project. MOC seems to be
I have encountered a very strange problem in using jQuery load() . I used
I have a very strange problem. I am using jQuery to intercept a particular
I'm encountering a very strange problem using g++ 4.1.2. I have a very basic
developers! I have very strange problem. My project has DLL writen in C++ and
I have a very strange problem. (fyi - I'm using forms authentication and manually
Hi. I have a very strange problem. When I rightclick on my project in
I have very strange problem. I'm using IIS 7.0 Integrated mode for my application.

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.