#{bean.list.size} 导致 java.lang.NumberFormatException:对于输入字符串:"size"

#{bean.list.size} causes java.lang.NumberFormatException: For input string: "size"

这是我的 xhtml,我的渲染属性有问题。我收到有关列表 "size" 的错误。只有当一些数据 found.Couldnt 找到如何修复 it.Thank 你的时间时,我才想呈现数据表。

<ui:composition template="/pages/admin/admin.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui">

    <ui:define name="center">
        <h:form id="updateform">
            <p:growl id="messages"/>
            <p:panel id="pnlUpdateUser" header="#{menu['menu.admin.usermanager.updateuser']}">
                <p:panelGrid columns="2" styleClass="cm_ui-panel-grid">
                    <p:outputLabel value="#{menu['menu.admin.createuser.name']}" styleClass="cm_ui-output-label"/>
                    <p:inputText styleClass="cm_input-text" value="#{userMB.userQuery.name}" required="true" />

                    <p:outputLabel value="#{menu['menu.admin.createuser.surname']}" styleClass="cm_ui-output-label"/>
                    <p:inputText styleClass="cm_input-text" value="#{userMB.userQuery.surname}" />

                    <f:facet name="footer">
                        <p:commandButton value="#{menu.search}" actionListener="#{userMB.queryUsers}" update="pnluserresult"/>
                    </f:facet>
                </p:panelGrid>
            </p:panel>
            <p:panelGrid id="pnluserresult" columns="1"
                    rendered="#{(userMB.users.size eq 0) or (userMB.users.size > 0)} ">
                <p:dataTable id="userresulttable" var="user" value="#{userMB.users}">
                    <f:facet name="header">
                        <p:outputLabel value="#{menu['menu.admin.updateuser.list']}"/>
                    </f:facet>
                    <p:column headerText="#{menu['menu.admin.createuser.id']}">
                        <h:outputText value="#{user.id}" />
                    </p:column>
                    <p:column headerText="#{menu['menu.admin.createuser.name']}">
                        <h:outputText value="#{user.name}" />
                    </p:column>
                    <p:column headerText="#{menu['menu.admin.createuser.surname']}">
                        <h:outputText value="#{user.surname}" />
                    </p:column>
                    <p:column headerText="#{menu['menu.admin.createuser.grade']}">
                        <h:outputText value="#{user.grade}" />
                    </p:column>
                </p:dataTable>
            </p:panelGrid>
        </h:form>
    </ui:define>
</ui:composition>

这是我的异常堆栈跟踪...

    java.lang.NumberFormatException: For input string: "size"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:492)
    at java.lang.Integer.parseInt(Integer.java:527)
    at javax.el.ListELResolver.coerce(ListELResolver.java:157)
    at javax.el.ListELResolver.getValue(ListELResolver.java:70)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:167)
    at org.apache.el.parser.AstEqual.getValue(AstEqual.java:37)
    at org.apache.el.parser.AstOr.getValue(AstOr.java:37)
    at org.apache.el.parser.AstDeferredExpression.getValue(AstDeferredExpression.java:43)
    at org.apache.el.parser.AstCompositeExpression.getValue(AstCompositeExpression.java:49)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:187)
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
    at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:457)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1850)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889)
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:79)
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:66)
    at org.primefaces.component.layout.LayoutUnitRenderer.encodeEnd(LayoutUnitRenderer.java:49)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:456)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.software.cm.others.filters.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:23)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

您的问题是您在#{userMB.users.size} 之后缺少括号。应该修改成这样:

<p:panelGrid id="pnluserresult" columns="1"
                rendered="#{(userMB.users.size() eq 0) or (userMB.users.size() gt 0)} ">

在某些情况下,就像我的情况一样,可能需要用另一种方式检查它,我遇到了同样的问题,但出于某种原因我仍然得到:

Servlet.service() for servlet Faces Servlet threw exception: java.lang.NumberFormatException: For input string: "size"

我正在使用 Java 8 和 JSF 2.0(这可能是原因吗?)

另一种检查列表 属性 是否为 null 的方法,在 getter 中如果没有元素则确保为 return null,而在 JSF 中页面检查如下:

rendered="#{(varProcInstance.products != null)}"

正如我所说,这对我有用,因为唯一的答案没有。

此致,