java.lang.IllegalArgumentException: FacesContext must not be null 错误分析及解决

WildFlly 10默认支持JSF 2.2。

为WildFlly 10添加Spring模块时,module.xml文件中默认依赖的是JSF 2.2。

对于JSF 2.1的应用,如果其Managed Bean使用Spring框架的标注定义,如@org.springframework.stereotype.Component。部署的时候没有问题,但是在访问JSF页面时,会在抛出如下异常:

14:34:38,592 ERROR [default task-22][render_portlet_jsp:132] null
java.lang.IllegalArgumentException: FacesContext must not be null
        at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
        at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
        at org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
        at org.jboss.el.parser.AstValue.getValue(AstValue.java:63)
        at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
        at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
        at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:227)
        at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:150)
        at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85)
        at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
        at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:207)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1822)
        at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:447)
        at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
        at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:286)
        at com.liferay.faces.bridge.application.internal.ViewHandlerCompatImpl.renderView(ViewHandlerCompatImpl.java:51)
        at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:286)
        at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:286)
        at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:286)

其根源在于Spring模块依赖的JSF与应用中使用的JSF版本不一致。

修改Spring模块的module.xml文件如下即可:

替换

    <dependencies>
…
    		<module name="javax.faces.api"/>
    </dependencies>

    <dependencies>
…
    		<module name="javax.faces.api" slot="2.1"/>
    </dependencies>


参考文献:

http://forum.spring.io/forum/spring-projects/web/125931-jsf2-and-spring3-facescontext-must-not-be-null-with-springbeanfaceselresolver


你可能感兴趣的:(spring,JSF,wildfly,FacesContext)