找不到具有[1]参数的方法[attribute]



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

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

以下是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)

我真的不明白为什么要扔它。有人能解释一下我的错误吗?

谢谢。

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

#{sessions.getAttribute(login)}

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


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

#{session.getAttribute(login)}

我找到了一个变通方法

<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;
        }
    }
}

相关内容

  • 没有找到相关文章

最新更新