0

我为我的 JSF 应用程序实现了一个 HttpSessionListener。

我的应用程序的所有活动会话都有一个List<HttpSession>对象。在每个 SessionCreated 事件中,我将实际添加HttpSession到 thisList中。登录时,我向活动会话添加了一些属性,并在List. 到目前为止一切顺利,它正在工作。但是现在我创建了一个 PrimeFaces 数据表来显示哪个会话是未使用的会话。这意味着哪个 Session 没有登录属性。Login 属性是一个简单的字符串对象。

这是数据表的实现:

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

我真的不明白为什么会抛出它。请有人可以解释我的错误吗?

谢谢。

4

2 回答 2

3

正确的方法名称是getAttribute(),不是attribute()

#{sessions.getAttribute(login)}

请记住,您调用的是方法,而不是访问属性,因此get前缀仍然是必需的。


与具体问题无关,我会修复var="sessions"var="session",因为它只涉及一个会话实例,而不是多个。否则你的代码读起来很混乱(即它不是自我记录的)。

#{session.getAttribute(login)}
于 2013-02-06T13:44:46.750 回答
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;
        }
    }
}
于 2016-08-25T14:34:28.333 回答