我正在使用JSF和模板。当我在URL上传递无效参数时,菜单模板的部分将获得java.lang.NullPointerException
。它没有对<f:viewParam>
进行验证。如果我通过有效参数,那一切都没问题。它在执行托管bean的setter之前呈现模板的其他组件。
当我使用f:param添加h:link到page menu.xhtml或类似内容时会发生这种情况。
效果正常的网址:
http://localhost:8080/MiWebApp/maincontent/myWebPage.xhtml?myWebParam=aaa&myWebHeaderParam=bb
无效的网址:
http://localhost:8080/MiWebApp/maincontent/myWebPage.xhtml?myWebParam=aaa&myWebHeaderParam=zzzzzzzzzzzzz
这是网络应用的一个示例:
的template.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<f:view contentType="text/html" id="fview">
<f:metadata>
<ui:insert name="metadata" />
</f:metadata>
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Page template with PrimeFaces</title>
<ui:debug />
</h:head>
<h:body>
<p:growl id="growl" life="3000" />
<p:layout fullPage="true">
<p:layoutUnit position="north" size="90" id="north" resizable="false"
style="min-width: 600px;"
styleClass="layoutHeader">
<ui:include src="header.xhtml" />
</p:layoutUnit>
<p:layoutUnit position="center" resizable="false">
<ui:insert name="content" />
</p:layoutUnit>
<p:layoutUnit position="east" id="west" resizable="false"style="height:580px;overflow:hidden;min-width:200px;" >
<ui:include src="menu.xhtml" />
</p:layoutUnit>
</p:layout>
</h:body>
</f:view>
</html>
header.xhtml
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:panelGroup layout="block">
<h:outputText value="myWebParam: #{myWebHeaderController.cp.myWebParam}"/>
<h:outputText value="myWebHeaderParam #{myWebHeaderController.myWebHeaderParam}"/>
</h:panelGroup>
</ui:composition>
名为menu.xhtml
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:panelGroup layout="block">
<h:outputText value="myWebParam: #{myWebMenuController.cp.myWebParam}"/>
<h:outputText value="myInput: #{myWebMenuController.myInput}"/>
</h:panelGroup>
<h:panelGroup layout="block">
<h:link value="hey link"
outcome="/maincontent/list/myWebPage">
<f:param name="myWebParam" value="#{myWebMenuController.cp.myWebParam}"/>
<f:param name="myWebHeaderParam" value="#{myWebHeaderController.myWebHeaderParam}"/>
</h:link>
</h:panelGroup>
</ui:composition>
myWebPage.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
template="/templates/template.xhtml">
<ui:define name="metadata">
<f:metadata>
<f:viewParam id="myWebParam"
name="myWebParam"
required="true"
value="#{myWebCommonParamController.myWebParam}">
<f:validateLength minimum="1"
maximum="3"/>
<f:validateRegex pattern="aaa"/>
</f:viewParam>
<f:viewParam id="myWebHeaderParam"
name="myWebHeaderParam"
required="true"
value="#{myWebHeaderController.myWebHeaderParam}">
<f:validateLength minimum="1"
maximum="2"/>
<f:validateRegex pattern="bb"/>
</f:viewParam>
</f:metadata>
</ui:define>
<ui:define name="content">
<f:view>
<h:panelGroup layout="block">
<h:outputText value="Hello, you are on myWebPage"/>
<h:outputText value="myWebParam: #{myWebCommonParamController.myWebParam}"/>
<h:outputText value="myWebHeaderParam: #{myWebHeaderController.myWebHeaderParam}"/>
</h:panelGroup>
</f:view>
</ui:define>
</ui:composition>
豆子:
MyWebCommonParamController
@ManagedBean
@ViewScoped
public class MyWebCommonParamController {
private String myWebParam;
public MyWebCommonParamController() {
}
public String getMyWebParam() {
return myWebParam;
}
public void setMyWebParam(String myWebParam) {
this.myWebParam = myWebParam;
}
}
MyWebHeaderController
@ManagedBean
@RequestScoped
public class MyWebHeaderController {
@ManagedProperty(value = "#{myWebCommonParamController}")
private MyWebCommonParamController cp;
private String myWebHeaderParam;
public MyWebHeaderController() {
}
public MyWebCommonParamController getCp() {
return cp;
}
public void setCp(MyWebCommonParamController cp) {
this.cp = cp;
}
public String getMyWebHeaderParam() {
return myWebHeaderParam;
}
public void setMyWebHeaderParam(String myWebHeaderParam) {
this.myWebHeaderParam = myWebHeaderParam;
}
}
MyWebMenuController
@ManagedBean
@RequestScoped
public class MyWebMenuController {
@ManagedProperty(value = "#{myWebCommonParamController}")
private MyWebCommonParamController cp;
private String myInput;
public MyWebMenuController() {
}
public MyWebCommonParamController getCp() {
return cp;
}
public void setCp(MyWebCommonParamController cp) {
this.cp = cp;
}
public String getMyInput() {
return myInput;
}
public void setMyInput(String myInput) {
this.myInput = myInput;
}
}
控制台错误:
08:41:23,997 WARNING [javax.faces] (default task-1) Definiendo valor de atributo no serializable en ViewMap: (clave: myWebCommonParamController, clase de valor: com.mywebapp.MyWebCommonParamController)
08:41:28,879 WARNING [javax.faces] (default task-10) Definiendo valor de atributo no serializable en ViewMap: (clave: myWebCommonParamController, clase de valor: com.mywebapp.MyWebCommonParamController)
08:41:28,918 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (default task-10) Error Rendering View[/maincontent/myWebPage.xhtml]: java.lang.NullPointerException
at java.net.URLEncoder.encode(URLEncoder.java:205) [rt.jar:1.7.0_72]
at com.sun.faces.context.UrlBuilder.addValuesToParameter(UrlBuilder.java:318) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.context.UrlBuilder.addParameters(UrlBuilder.java:127) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.context.ExternalContextImpl.encodeBookmarkableURL(ExternalContextImpl.java:1045) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.application.view.MultiViewHandler.getBookmarkableURL(MultiViewHandler.java:407) [jsf-impl-2.2.6-jbossorg-4.jar:]
at javax.faces.application.ViewHandlerWrapper.getBookmarkableURL(ViewHandlerWrapper.java:272) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at org.jboss.weld.jsf.ConversationAwareViewHandler.getBookmarkableURL(ConversationAwareViewHandler.java:132) [weld-core-jsf-2.1.2.Final.jar:2014-01-09 09:23]
at javax.faces.application.ViewHandlerWrapper.getBookmarkableURL(ViewHandlerWrapper.java:272) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.application.ViewHandlerWrapper.getBookmarkableURL(ViewHandlerWrapper.java:272) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at com.sun.faces.renderkit.html_basic.OutcomeTargetRenderer.getEncodedTargetURL(OutcomeTargetRenderer.java:194) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.renderkit.html_basic.OutcomeTargetLinkRenderer.renderAsActive(OutcomeTargetLinkRenderer.java:158) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.renderkit.html_basic.OutcomeTargetLinkRenderer.encodeBegin(OutcomeTargetLinkRenderer.java:96) [jsf-impl-2.2.6-jbossorg-4.jar:]
at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:864) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:302) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:115) [jsf-impl-2.2.6-jbossorg-4.jar:]
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:79) [primefaces-5.1.jar:5.1]
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:66) [primefaces-5.1.jar:5.1]
at org.primefaces.component.layout.LayoutUnitRenderer.encodeEnd(LayoutUnitRenderer.java:49) [primefaces-5.1.jar:5.1]
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1864) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1860) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1860) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1860) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:461) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133) [jsf-impl-2.2.6-jbossorg-4.jar:]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) [jsf-impl-2.2.6-jbossorg-4.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) [shiro-web-1.2.1.jar:1.2.1]
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) [shiro-web-1.2.1.jar:1.2.1]
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) [shiro-core-1.2.1.jar:1.2.1]
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) [shiro-core-1.2.1.jar:1.2.1]
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383) [shiro-core-1.2.1.jar:1.2.1]
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) [shiro-web-1.2.1.jar:1.2.1]
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) [shiro-web-1.2.1.jar:1.2.1]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_72]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_72]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_72]
08:41:28,939 FATAL [javax.enterprise.resource.webcontainer.jsf.context] (default task-10) JSF1073: se ha interceptado java.lang.NullPointerException durante el procesamiento de RENDER_RESPONSE 6 : UIComponent-ClientId=, Mensaje=null
08:41:28,939 FATAL [javax.enterprise.resource.webcontainer.jsf.context] (default task-10) No associated message: java.lang.NullPointerException
at java.net.URLEncoder.encode(URLEncoder.java:205) [rt.jar:1.7.0_72]
at com.sun.faces.context.UrlBuilder.addValuesToParameter(UrlBuilder.java:318) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.context.UrlBuilder.addParameters(UrlBuilder.java:127) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.context.ExternalContextImpl.encodeBookmarkableURL(ExternalContextImpl.java:1045) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.application.view.MultiViewHandler.getBookmarkableURL(MultiViewHandler.java:407) [jsf-impl-2.2.6-jbossorg-4.jar:]
at javax.faces.application.ViewHandlerWrapper.getBookmarkableURL(ViewHandlerWrapper.java:272) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at org.jboss.weld.jsf.ConversationAwareViewHandler.getBookmarkableURL(ConversationAwareViewHandler.java:132) [weld-core-jsf-2.1.2.Final.jar:2014-01-09 09:23]
at javax.faces.application.ViewHandlerWrapper.getBookmarkableURL(ViewHandlerWrapper.java:272) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.application.ViewHandlerWrapper.getBookmarkableURL(ViewHandlerWrapper.java:272) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at com.sun.faces.renderkit.html_basic.OutcomeTargetRenderer.getEncodedTargetURL(OutcomeTargetRenderer.java:194) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.renderkit.html_basic.OutcomeTargetLinkRenderer.renderAsActive(OutcomeTargetLinkRenderer.java:158) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.renderkit.html_basic.OutcomeTargetLinkRenderer.encodeBegin(OutcomeTargetLinkRenderer.java:96) [jsf-impl-2.2.6-jbossorg-4.jar:]
at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:864) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:302) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:115) [jsf-impl-2.2.6-jbossorg-4.jar:]
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:79) [primefaces-5.1.jar:5.1]
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:66) [primefaces-5.1.jar:5.1]
at org.primefaces.component.layout.LayoutUnitRenderer.encodeEnd(LayoutUnitRenderer.java:49) [primefaces-5.1.jar:5.1]
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1864) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1860) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1860) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1860) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:461) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133) [jsf-impl-2.2.6-jbossorg-4.jar:]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) [jsf-impl-2.2.6-jbossorg-4.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) [shiro-web-1.2.1.jar:1.2.1]
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) [shiro-web-1.2.1.jar:1.2.1]
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) [shiro-core-1.2.1.jar:1.2.1]
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) [shiro-core-1.2.1.jar:1.2.1]
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383) [shiro-core-1.2.1.jar:1.2.1]
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) [shiro-web-1.2.1.jar:1.2.1]
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) [shiro-web-1.2.1.jar:1.2.1]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_72]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_72]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_72]
答案 0 :(得分:1)
这是正常行为。验证工作正常但是一旦验证了params,继续渲染视图并获取错误,但现在您使用渲染视图的空值。
解决方案:
<o:viewParamValidationFailed>
允许开发人员使用重定向或HTTP错误状态处理视图参数验证失败,可选择分别使用flash消息或HTTP错误消息。
<f:metadata>
<f:viewParam name="foo" converter="javax.faces.Long">
<o:viewParamValidationFailed sendError="400" />
</f:viewParam>
<f:viewParam name="bar" converter="javax.faces.Long">
<o:viewParamValidationFailed sendError="400" message="Invalid bar!"/>
</f:viewParam>
<f:viewParam name="baz" converter="javax.faces.Long">
<o:viewParamValidationFailed sendRedirect="whatsnew" />
</f:viewParam>
<f:viewParam name="faz" converter="javax.faces.Long">
<o:viewParamValidationFailed sendRedirect="whatsnew" message="Invalid faz!" />
</f:viewParam>
<f:viewParam name="boo" converter="javax.faces.Long" />
<f:viewParam name="foz" converter="javax.faces.Long" />
<o:viewParamValidationFailed sendError="400" message="#{foz.valid ? null : 'Invalid foz!'}" />
</f:metadata>
答案 1 :(得分:1)
我注意到的一些事情:
更多且不需要id
属性。小心这些,不需要记住f:viewParam
或f:view
由于您没有包含导入行,我必须同时写两个:
@javax.annotation.ManagedBean
适用于POJO(普通旧Java对象,不适用于&#34;控制器&#34;(支持bean)
@javax.faces.bean.ManagedBean
已弃用,来自JSF 2.0次。现在有@Named
和@javax.enterprise.context.SessionScoped
及其兄弟姐妹应该切换到的地方。
请记住,您必须将两个注释切换为&#34; new&#34; JSF 2.2注释,两个版本(2.0 / 2.2)的组合确实不工作!
这是一个不完整但有效的例子:
SomeContactSessionBean.java
@Named ("contactController")
@SessionScoped
public class SomeContactWebSessionBean implements Serializable {
private static final long serialVersionUID = 9876543210;
}
用于例如test.xhtml
<h:panelGroup styleClass="table_row" layout="block">
<div class="table_left_medium">
<h:outputLabel for="emailAddress" value="#{msg.ADMIN_PERSONAL_DATA_EMAIL_ADDRESS}" />
</div>
<div class="table_right_medium">
<h:inputText styleClass="input" id="emailAddress" size="10" maxlength="255" value="#{contactController.emailAddress}" validatorMessage="#{msg.ENTERED_EMAIL_ADDRESS_IS_INVALID}">
<f:validator validatorId="EmailAddressValidator" />
</h:inputText>
</div>
<div class="clear"></div>
</h:panelGroup>
msg
是我的消息包,它被加载到一个中央&#34; master&#34;模板:
<f:loadBundle var="msg" basename="org.example.localization.bundle" />
好的,这并没有完全回答你的问题,但可能会给你提示如何清理和升级你的代码......: - )
现在,当我有像http://some-host/jexample-war/faces/show_contact.xhtml?contactId=123
我查看自定义转换器,但首先我这样做:
show_contact.xhtml
<ui:define name="metadata">
<f:metadata>
<f:viewParam name="contactId" value="#{beanHelper.contact}" converter="ContactConverter" required="true" requiredMessage="#{msg.ERROR_PARAMETER_CONTACT_ID_NOT_SET}" converterMessage="#{msg.PARAMETER_CONTACT_ID_INVALID}" />
<f:viewAction onPostback="true" action="#{beanHelper.copyContactToController()}" />
</f:metadata>
</ui:define>
SomeContactConverter.java
:
@FacesConverter (value = "ContactConverter")
public class SomeContactConverter implements Converter {
private static ContactSessionBeanRemote CONTACT_BEAN; // My EJB!
public SomeContactConverter () {
}
@Override
public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
// Is the value null or empty?
if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
// Log message
// Return null
return null;
}
// Is the bean there?
// @TODO Requires this synchronization or is it (sync) confusing the container?
if (null == SomeContactConverter.CONTACT_BEAN) {
// Try to get it
try {
// Get initial context
Context initialContext = new InitialContext();
// ... and user controller
SomeContactConverter.CONTACT_BEAN = (ContactSessionBeanRemote) initialContext.lookup("java:global/jexample-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
} catch (final NamingException ex) {
// Continue to throw it
throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
}
}
// Init instance
Contact contact = null;
// Try to parse the value as long
try {
Long contactId = Long.valueOf(submittedValue);
} catch (final NumberFormatException ex) {
// Throw again
throw new ConverterException(ex);
} catch (final ContactNotFoundException ex) {
// Log message ... Contact was not found, maybe show error message?
}
// Return it
return contact;
}
@Override
public String getAsString (final FacesContext context, final UIComponent component, final Object value) {
// Is the object null?
if ((null == value) || (String.valueOf(value).isEmpty())) {
// Is null
return ""; //NOI18N
} else if (!(value instanceof Contact)) {
// Not same interface
throw new IllegalArgumentException(MessageFormat.format("value[]={0} does not implement Contact.", value.getClass().getSimpleName())); //NOI18N
}
// Return id number
return String.valueOf(((Contact) value).getContactId());
}
}
请注意Contact
和远程接口再次是自定义接口,而不是JSF / EJB的一部分......; - )
现在你看到了#beanHelper
。这基本上看起来像:
SomeWebRequestHelperBean.java
@Named ("beanHelper")
@RequestScoped
public class SomeWebRequestHelperBean implements Serializable {
/**
* Serial number
*/
private static final long serialVersionUID = 1234567890L;
/**
* Administrative contact controller
*/
@Inject
private SomeContactWebRequestController contactController;
/**
* Contact instance
*/
private Contact contact;
public void copyContactToController () {
// Validate contact instance
if (this.getContact() == null) {
// Throw NPE
throw new NullPointerException("this.contact is null"); //NOI18N
} else if (this.getContact().getContactId() == null) {
// Throw NPE again
throw new NullPointerException("this.contact.contactId is null"); //NOI18N
} else if (this.getContact().getContactId() < 1) {
// Not valid
throw new IllegalStateException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId())); //NOI18N
}
// @deprecated Copy all fields to controller so it can be used in JSF tags as shown above
// @TODO rewrite this to CDI event
this.contactController.copyContactToController(this.getContact());
}
public Contact getContact () {
return this.contact; // <f:viewParam> "triggers" to call this!
}
public void setContact (final Contact contact) {
this.contact = contact; // <f:viewParam> "triggers" to call this!
}
}
请注意,这是不完整的,但它应该给你一些提示可能是错误的。