h:复合组件中没有值的selectOneMenu会抛出nullpointerexception

时间:2016-02-22 11:43:21

标签: jsf nullpointerexception composite-component selectonemenu is-empty

我在复合组件中有一个selectOneMenu,如下所示:

<!-- INTERFACE -->
<cc:interface>
    <cc:attribute name="label"/>
    <cc:attribute name="value"/>
</cc:interface>

<!-- IMPLEMENTATION -->
<cc:implementation>
        <h:outputLabel value="#{cc.attrs.label}" for="input"/>
        <h:selectOneMenu id="input" value="#{cc.attrs.value}"  styleClass="width100">
        </h:selectOneMenu>
        <h:message id="#{cc.attrs.id}-message" for="input" />  
</cc:implementation>

如果我在使用此组件时未指定值属性:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:ezcomp="http://xmlns.jcp.org/jsf/composite/ezcomp"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <f:view contentType="text/html">
        <h:body>
            <h:form id="myform">
                <ezcomp:input label="Some label"  >
                </ezcomp:input>
                <p:commandButton value="Save" />
            </h:form>    
        </h:body>
    </f:view>
</html>

提交表单时我得到nullpointerexception。:

12:25:23,882 FATAL [javax.enterprise.resource.webcontainer.jsf.context] (default task-24) java.lang.NullPointerException: javax.faces.component.UpdateModelException: java.lang.NullPointerException
    at javax.faces.component.UIInput.updateModel(UIInput.java:866)
    at javax.faces.component.UIInput.processUpdates(UIInput.java:749)
    at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1290)
    at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1290)
    at javax.faces.component.UIForm.processUpdates(UIForm.java:281)
    at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1290)
    at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1290)
    at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:1254)
    at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:78)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:654)
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86)
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:72)
    at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
    at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:282)
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:261)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:80)
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:172)
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199)
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:774)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
    at javax.faces.component.UIComponentBase$AttributesMap.put(UIComponentBase.java:2466)
    at javax.faces.component.UIComponentBase$AttributesMap.put(UIComponentBase.java:2335)
    at com.sun.faces.el.CompositeComponentAttributesELResolver$ExpressionEvalMap.put(CompositeComponentAttributesELResolver.java:415)
    at com.sun.faces.el.CompositeComponentAttributesELResolver$ExpressionEvalMap.put(CompositeComponentAttributesELResolver.java:331)
    at javax.el.MapELResolver.setValue(MapELResolver.java:267)
    at com.sun.faces.el.DemuxCompositeELResolver._setValue(DemuxCompositeELResolver.java:255)
    at com.sun.faces.el.DemuxCompositeELResolver.setValue(DemuxCompositeELResolver.java:281)
    at com.sun.el.parser.AstValue.setValue(AstValue.java:255)
    at com.sun.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:294)
    at org.jboss.weld.el.WeldValueExpression.setValue(WeldValueExpression.java:64)
    at org.jboss.weld.el.WeldValueExpression.setValue(WeldValueExpression.java:64)
    at com.sun.faces.facelets.el.ContextualCompositeValueExpression.setValue(ContextualCompositeValueExpression.java:172)
    at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131)
    at javax.faces.component.UIInput.updateModel(UIInput.java:832)
    ... 38 more

我使用jsf 2.2(使用Wildfly 9.0.1)。如果我使用inputText而不是selectOneMenu它运行良好。它不依赖于select没有选项(从这个例子中不明显,但是我原来更复杂的一个证明了它),它有效地取决于具有空值属性的selectOneMenu。如果我指定一个值,它也可以正常工作,因此它不是一个大问题,但在开发过程中会让事情变得更加不舒服。你知道为什么会这样吗?任何解决方案,解决方法?感谢。

0 个答案:

没有答案