我为我的JSF App实现了一个HttpSessionListener。
我的应用程序的所有活动会话都有一个List<HttpSession>
对象。在每个SessionCreated事件中,我将实际HttpSession
添加到此List
。登录时,我将一些属性添加到活动会话中,并替换List
中修改后的会话。到目前为止一切顺利,它正在发挥作用。但现在我创建了一个PrimeFaces Datatable来显示哪个Session是未使用的Session。这意味着哪个Session没有login属性。 Login属性是一个简单的String对象。
以下是Datatable的实现:
<p:dataTable var="sessions" value="#{applicationListener.sessions}" paginator="false" id="dt_sessions">
<f:facet name="header">
Sessions
</f:facet>
<p:column headerText="ID" style="font-size: 12px; text-align: center" >
#{sessions.id}
</p:column>
<p:column headerText="Name" style="font-size: 12px; text-align: center" >
#{sessions.attribute(login)}
</p:column>
</p:dataTable>
Tomcat抛出HTTP 500 Stacktrace:
Feb 6, 2013 2:00:50 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [] threw exception [/rmlcon.xhtml: Unable to find method [attribute] with [1] parameters] with root cause
javax.el.ELException: /rmlcon.xhtml: Unable to find method [attribute] with [1] parameters
at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:88)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at org.primefaces.component.datatable.DataTableRenderer.encodeRegularCell(DataTableRenderer.java:741)
at org.primefaces.component.datatable.DataTableRenderer.encodeRow(DataTableRenderer.java:693)
at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:601)
at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:220)
at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:192)
at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:74)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:424)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
我真的不明白为什么抛出它。有人可以解释我的错误吗?
感谢。
答案 0 :(得分:3)
正确的方法名称是getAttribute()
,而不是attribute()
。
#{sessions.getAttribute(login)}
请记住,您正在调用方法,而不是访问属性,因此get
前缀仍然是必需的。
无关,我将var="sessions"
修复为var="session"
,因为它只涉及一个会话实例,而不是多个会话实例。否则你的代码看起来很混乱(即它不是自我记录的)。
#{session.getAttribute(login)}
答案 1 :(得分:1)
我找到了解决方法
<p:inputText id="valore" value="#{myBean.getValObj(0).val}" />
豆是
public class MyBean{
public ValObj getValObj(int idx){
return new ValObj(this, idx);
}
public class ValObj{
MyBean bean;
int idx = -1;
public ValObj(MyBean bean, int idx){
this.bean = bean;
this.idx = idx;
}
public double getVal(){
return valori[idx];
}
public void setVal(double val){
valori[idx] = val;
}
}
}