- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
JSF 2.0 项目中的 SessionScoped bean 有一个非常奇怪的问题。使用 Netbeans 6.9.1、Glassfish 3 服务器和 PrimeFaces 3 作为 JSF 组件库。
这是一些代码:
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;
}
}
<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>
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
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
最佳答案
你用错了@SessionScoped
注解。
如果您使用 JSF @ManagedBean
注册了 bean注解,则需要导入 @SessionScoped
来自 JSF ( javax.faces
) 包,如下所示:
import javax.faces.bean.SessionScoped;
当您在 JSF 托管 bean 上错误地使用 CDI 范围时,JSF 托管 bean 实际上没有 JSF 范围,它会回退到其默认值
@RequestScoped
,它在每个 HTTP 请求中创建一个新实例。
@Named
注册了 bean注解,则需要导入
@SessionScoped
来自 CDI (
javax.enterprise.context
) 包,如下所示:
import javax.enterprise.context.SessionScoped;
当您在 CDI 托管 bean 上错误地使用 JSF 范围时,CDI 托管 bean 实际上没有 CDI 范围,它会回退到其默认值
@Dependent
作用域,它在每个 EL 表达式中创建一个新实例。
关于jsf - @SessionScoped bean 失去作用域并一直被重新创建,字段变为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9470440/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!