Changing the browser language after entering the `en` value [duplicate] - jsf

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?

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?

Related

java CDI doesn't work correctly [duplicate]

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?
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?

CDI interceptor not fired when JSF managed bean method is invoked

This my interceptor study case, but it doesn't fire.
The annotation for interceptor
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.interceptor.InterceptorBinding;
#Inherited
#InterceptorBinding
#Retention(RUNTIME)
#Target({METHOD, TYPE})
public #interface LogInterceptor {
}
The Implementation for interceptor
import javax.annotation.Priority;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
#Interceptor
#LogInterceptor
#Priority(Interceptor.Priority.APPLICATION)
public class LogInterceptorImpl {
#AroundInvoke
public Object log(InvocationContext context) {
Object o = null;
try {
System.out.println("START");
o = context.proceed();
System.out.println("END");
} catch (Exception e) {
e.printStackTrace();
}
return o;
}
}
The controller
import modelo.Post;
import interceptor.LogInterceptor;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
#ManagedBean(name = "postController")
#SessionScoped
public class PostController implements Serializable {
private List<Post> items = null;
private Post selected;
public PostController() {
MyFacade facade = new MyFacade();
items = facade.getItems();
}
#LogInterceptor
public List<Post> getItems() {
return items;
}
}
The glassfish log
Informações: EclipseLink, version: Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd
Informações: file:/C:/Users/f9921257/Documents/NetBeansProjects/estudo/build/web/WEB-INF/classes/_estudoPU login successful
Informações: Portable JNDI names for EJB PostFacade: [java:global/estudo/PostFacade!facade.PostFacade, java:global/estudo/PostFacade]
Informações: Portable JNDI names for EJB CategoriaFacade: [java:global/estudo/CategoriaFacade!facade.CategoriaFacade, java:global/estudo/CategoriaFacade]
Informações: WELD-000900: 2.2.2 (Final)
WARN: WELD-001700: Interceptor annotation class javax.ejb.PostActivate not found, interception based on it is not enabled
WARN: WELD-001700: Interceptor annotation class javax.ejb.PrePassivate not found, interception based on it is not enabled
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(#Observes ProcessAnnotatedType<Object>, BeanManager) receives events for all annotated types. Consider restricting events using #WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.gf.cdi.internal.CdiComponentProvider.processAnnotatedType(#Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using #WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(#Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using #WithAnnotations or a generic type with bounds.
Informações: Inicializando Mojarra 2.2.7 ( 20140610-1547 https://svn.java.net/svn/mojarra~svn/tags/2.2.7#13362) para o contexto '/estudo'
Informações: Monitoring jndi:/server/estudo/WEB-INF/faces-config.xml for modifications
Informações: Running on PrimeFaces 5.0
Informações: Loading application [estudo] at [/estudo]
Informações: estudo was successfully deployed in 13.298 milliseconds.
The marks "START" and "END" put on LogInterceptorImpl does not appear in the log file. Why they doesn't fire?
You need to use #javax.inject.Named annotation instead of #ManagedBean:
#Named("postController")
#SessionScoped
public class PostController
Also add #AroundInvoke to mark the interceptor method:
#Interceptor
#LogInterceptor
public class LogInterceptorImpl {
#AroundInvoke
public Object log(InvocationContext context) {
...
}
}
And the last step, you need to enable the interceptor in beans.xml, otherwise the interceptor would be ignored:
beans.xml
<beans>
<interceptors>
<class>com.nameofyourpackage.LogInterceptorImpl </class>
</interceptors>
</beans>
Explanation for using #Named instead of #ManagedBean
Both annotations mean essentially the same - they give a textual name to a bean, so that it may be accessed in a JSF page. However, beans marked #ManagedBean are created by the JSF subsystem and CDI annotations are ignored (such as SessionScoped or interceptor qualifiers, such as your LogInterceptor). Beans marked #Named can take full advantage of CDI, while you cannot use JSF specific annotations, like #ManagedProperty (you should use #Inject with CDI). This is not a problem as #ManagedProperty and #ManagedBean are both deprecated and there is always a way how to accomplish the same with CDI. This is discussed in more detail here: Backing beans (#ManagedBean) or CDI Beans (#Named)?

Use EntityManager in Validator [duplicate]

How can I inject a dependency like #EJB, #PersistenceContext, #Inject, #AutoWired, etc in a #FacesValidator? In my specific case I need to inject a Spring managed bean via #AutoWired:
#FacesValidator("emailExistValidator")
public class EmailExistValidator implements Validator {
#Autowired
private UserDao userDao;
// ...
}
However, it didn't get injected and it remains null, resulting in java.lang.NullPointerException.
It seems that #EJB, #PersistenceContext and #Inject also doesn't work.
How do I inject a service dependency in my validator so that I can access the DB?
JSF 2.3+
If you're already on JSF 2.3 or newer, and want to inject CDI-supported artifacts via e.g. #EJB, #PersistenceContext or #Inject, then simply add managed=true to the #FacesValidator annotation to make it CDI-managed.
#FacesValidator(value="emailExistValidator", managed=true)
JSF 2.2-
If you're not on JSF 2.3 or newer yet, then you basically need to make it a managed bean. Use Spring's #Component, CDI's #Named or JSF's #ManagedBean instead of #FacesValidator in order to make it a managed bean and thus eligible for dependency injection.
E.g., assuming that you want to use CDI's #Named:
#Named
#ApplicationScoped
public class EmailExistValidator implements Validator {
// ...
}
You also need to reference it as a managed bean by #{name} in EL instead of as a validator ID in hardcoded string. Thus, so
<h:inputText ... validator="#{emailExistValidator.validate}" />
instead of
<h:inputText ... validator="emailExistValidator" />
or
<f:validator binding="#{emailExistValidator}" />
instead of
<f:validator validatorId="emailExistValidator" />
For EJBs there's a workaround by manually grabbing it from JNDI, see also Getting an #EJB in #FacesConverter and #FacesValidator.
If you happen to use JSF utility library OmniFaces, since version 1.6 it adds transparent support for using #Inject and #EJB in a #FacesValidator class without any additional configuration or annotations. See also the CDI #FacesValidator showcase example.
See also:
CDI Injection into a FacesConverter
What's new in JSF 2.2 - Injection
You can now inject into JSF validators if you're using Java EE 8 and/or JSF 2.3.
Tested using Mojarra 2.3.9.payara-p2 on Payara Server 5.192 #badassfish.
<?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:h="http://xmlns.jcp.org/jsf/html">
<h:body>
Hello from Facelets
<h:form>
<h:messages/>
<h:inputText value="#{someBean.txtField}" validator="someValidator"/>
</h:form>
</h:body>
</html>
import javax.inject.Named;
import javax.enterprise.context.Dependent;
#Named(value = "someBean")
#Dependent
public class SomeBean {
private String txtField;
public String getTxtField() {
return txtField;
}
public void setTxtField(String txtField) {
this.txtField = txtField;
}
}
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
import javax.inject.Inject;
#FacesValidator(value = "someValidator", managed = true)
public class CustomValidator implements Validator<String> {
#Inject
NewClass newClass;
#Override
public void validate(FacesContext context, UIComponent component, String value)
throws ValidatorException {
System.out.println("validator running");
System.out.println("injected bean: " + newClass);
if (value != null && value.equals("badvalue")) {
throw new ValidatorException(new FacesMessage(newClass.getMessage()));
}
}
}
public class NewClass {
public String getMessage() {
return "secret message";
}
}
import javax.faces.annotation.FacesConfig;
// WITHOUT THIS INJECTION WILL NOT WORK!
#FacesConfig(version = FacesConfig.Version.JSF_2_3)
public class ConfigurationBean {
}
Should render something like:
I banged my head on the wall for about an hour before realizing the need for ConfigurationBean. From the documentation:
FacesConfig.Version.JSF_2_3
This value indicates CDI should be used for EL resolution as well as enabling JSF CDI injection, as specified in Section 5.6.3 "CDI for EL Resolution" and Section 5.9 "CDI Integration"
And from this GitHub issue, https://github.com/eclipse-ee4j/glassfish/issues/22094:
By default, JSF 2.3 runs in a compatibility mode with previous releases of JSF, unless a CDI managed bean is included in the application with the annotation #javax.faces.annotation.FacesConfig. To switch into a JSF 2.3 mode you will need a configuration bean like below: (shows ConfigurationBean)
...
The fact that JSF needs to be switched into the "current version" was highly controversial. Pretty much the entire EG voted against that, but eventually we could not get around the backwards compatibility requirements that the JCP sets for Java EE and the spec lead enforces.

parameter with <f:viewParam> and FacesConverter from CDI

It's not clear to me why I'm getting this particular exception, it's a red-herring I think. The underlying problem could be related to the last line of the exception: MessageConverter.getAsObject..0 which should actually be 1501 (the Message ID). So, why does MessageConverter.getAsObject have the wrong id?
I think that this could be related to the Detail constructor, which is probably passing the wrong parameters to MessageConvert.getAsObject(), in particular the UIComponent object -- probably that reference needs to get instantiated.
relevant EL:
<h:outputLink id="link1" value="detail.xhtml">
<f:param name="id" value="#{m.getMessageNumber()}" />
<h:outputText value="#{m.getMessageNumber()}" />
</h:outputLink>
glassfish shows:
INFO: MessageConverter.getAsObject..1501
INFO: SingletonNNTP.forward..11
WARNING: 1501
java.lang.ArrayIndexOutOfBoundsException: 1501
at java.util.Arrays$ArrayList.get(Arrays.java:2866)
at net.bounceme.dur.nntp.SingletonNNTP.getMessage(SingletonNNTP.java:86)
at net.bounceme.dur.nntp.MessageConverter.getAsObject(MessageConverter.java:21)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:171)
at javax.faces.component.UIViewParameter.getConvertedValue(UIViewParameter.java:394)
at javax.faces.component.UIInput.validate(UIInput.java:960)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1233)
at javax.faces.component.UIInput.processValidators(UIInput.java:698)
at javax.faces.component.UIViewParameter.processValidators(UIViewParameter.java:273)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1172)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
INFO: MessageConverter.getAsObject..0
INFO: SingletonNNTP.forward..11
MessageConverter, I think that this class is fine so far is it goes:
package net.bounceme.dur.nntp;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.mail.Message;
#FacesConverter("messageConverter")
public class MessageConverter implements Converter {
private static final Logger logger = Logger.getLogger(MessageConverter.class.getName());
private static final Level level = Level.INFO;
private SingletonNNTP nntp = SingletonNNTP.INSTANCE;
#Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
logger.log(level, "MessageConverter.getAsObject..{0}", value);
Message message = nntp.getMessage(Integer.parseInt(value));
return message;
}
#Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
Message message = (Message) value;
return String.valueOf(message.getMessageNumber());
}
}
This is the problem class, Detail, with the constructor, in particular, being suspect:
package net.bounceme.dur.nntp;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import javax.mail.Message;
#Named
public class Detail {
private static final Logger logger = Logger.getLogger(Detail.class.getName());
private static final Level level = Level.INFO;
private int id = 0;
private Message message = null;
private SingletonNNTP nntp = SingletonNNTP.INSTANCE;
public Detail() {
MessageConverter mc = new MessageConverter();
FacesContext fc = FacesContext.getCurrentInstance();
String value = String.valueOf(id);
UIComponent ui = null;
Object obj = mc.getAsObject(fc, ui, value);
message = (Message) obj;
}
public int forward() {
logger.log(level, "Detail.forward..{0}", id);
id = id + 1;
logger.log(level, "..Detail.forward {0}", id);
return id;
}
public int back() {
logger.log(level, "Detail.back..{0}", id);
id = id - 1;
logger.log(level, "..Detail.back {0}", id);
return id;
}
public Message getMessage() {
return message;
}
public String getContent() throws Exception {
return message.getContent().toString();
}
}
reference:
viewparam-vs-managedpropertyvalue-param-id which doesn't quite seem to apply as I'm using CDI, #Named, and so cannot use #ManagedProperty, which is the "real" problem. I suppose I'm not seeing the CDI benefit, as #ManagedProperty looks very nice.
ProcessingGETRequestParameters has a, perhaps, key paragraph:
Yes, it's a #ManagedBean instead of #FacesConverter! How awkward, but
it's not possible to inject an #EJB inside a #FacesConverter in order
to do the DB interaction job. The same problem manifests when you use
the CDI #Inject to inject a property, you'd need to use #Named instead
of #FacesConverter. The Java EE/JSF/CDI guys are working on that for
the future JSF 2.2 version, see also JSF spec issue 763. If you really
need to have it to be a #FacesConverter (in order to utilize the
forClass attribute, for example), then you can always manually grab
the EJB from JNDI. See also the next chapter.
which, is, for my purposes, perhaps slightly off-topic as it's EJB related. However, perhaps that is the exact difficulty which I'm encountering?
The converter is supposed to be used in the <f:viewParam>.
<f:viewParam name="id" value="#{detail.message}" converter="messageConverter" />
This will basically convert the request parameter id to object Message and then set it in the property behind #{detail.message}. You should only supply a setter for it in the Detail class, I don't see any one in your bean.
You should not do the conversion job in the constructor of Detail class. You should only have a Message property, not the id or nntp. Remove the entire constructor.
#Named
public class Detail {
private Message message;
// Getters+setters+actions
}

#SessionScoped bean looses scope and gets recreated all the time, fields become null

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?
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?

Resources