根据BalusC在该主题中回答的第三个选项:
Performing a redirect, when conversion / validation associated with query parameters fails
我创建了以下解决方案:
<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facelettaglibrary_2_2.xsd">
<namespace>http://br.edu.ufca/web</namespace>
<tag>
<tag-name>viewParamValidationFailed</tag-name>
<handler-class>br.edu.ufca.criacaoemail.ViewParamValidationFailed</handler-class>
</tag>
</facelet-taglib>
public class ViewParamValidationFailed extends TagHandler implements ComponentSystemEventListener
{
private final String _outcome;
public ViewParamValidationFailed(TagConfig config)
{
super(config);
_outcome = getRequiredAttribute("outcome").getValue();
}
@Override
public void apply(FaceletContext context, UIComponent parent) throws IOException
{
if (parent instanceof UIViewRoot && !context.getFacesContext().isPostback())
{
((UIViewRoot) parent).subscribeToEvent(PostValidateEvent.class, this);
}
}
@Override
public void processEvent(ComponentSystemEvent event)
{
FacesContext context = FacesContext.getCurrentInstance();
if (!context.isPostback() && context.isValidationFailed())
{
ConfigurableNavigationHandler navigationHandler =
(ConfigurableNavigationHandler)
context.getApplication().getNavigationHandler();
navigationHandler.performNavigation(_outcome);
}
}
}
<f:metadata>
<ufca:viewParamValidationFailed outcome="checarTipoEmailInformado" />
<f:viewAction action="checarTipoEmailInformado" />
</f:metadata>
当加载URL时,标签处理程序在出现转换错误时正常工作,但在回发中(转换错误与否)我得到此异常:
08:21:37,809 ERROR [io.undertow.request] (default task-25) UT005023: Exception handling request to /email-servidores/criacaoemail.xhtml: javax.servlet.ServletException: java.lang.InstantiationException: br.edu.ufca.criacaoemail.ViewParamValidationFailed
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659) [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.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:1142) [rt.jar:1.8.0_20]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_20]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_20]
Caused by: java.lang.IllegalStateException: java.lang.InstantiationException: br.edu.ufca.criacaoemail.ViewParamValidationFailed
at javax.faces.component.StateHolderSaver.restore(StateHolderSaver.java:153) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent$ComponentSystemEventListenerAdapter.restoreState(UIComponent.java:2633) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.StateHolderSaver.restore(StateHolderSaver.java:165) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponentBase.restoreAttachedState(UIComponentBase.java:1793) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponentBase.restoreSystemEventListeners(UIComponentBase.java:1911) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponentBase.restoreState(UIComponentBase.java:1607) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIViewRoot.restoreState(UIViewRoot.java:1771) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at com.sun.faces.application.view.FaceletPartialStateManagementStrategy$2.visit(FaceletPartialStateManagementStrategy.java:380) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:151) [jsf-impl-2.2.6-jbossorg-4.jar:]
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1690) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at com.sun.faces.application.view.FaceletPartialStateManagementStrategy.restoreView(FaceletPartialStateManagementStrategy.java:367) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:138) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:123) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:590) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:150) [jsf-impl-2.2.6-jbossorg-4.jar:]
at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:353) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:353) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:197) [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.RestoreViewPhase.doPhase(RestoreViewPhase.java:121) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) [jsf-impl-2.2.6-jbossorg-4.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
... 26 more
Caused by: java.lang.InstantiationException: br.edu.ufca.criacaoemail.ViewParamValidationFailed
at java.lang.Class.newInstance(Class.java:418) [rt.jar:1.8.0_20]
at javax.faces.component.StateHolderSaver.restore(StateHolderSaver.java:150) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
... 47 more
Caused by: java.lang.NoSuchMethodException: br.edu.ufca.criacaoemail.ViewParamValidationFailed.<init>()
at java.lang.Class.getConstructor0(Class.java:3069) [rt.jar:1.8.0_20]
at java.lang.Class.newInstance(Class.java:403) [rt.jar:1.8.0_20]
... 48 more
正如您所看到的,JSF正在尝试创建标记处理程序ViewParamValidationFailed,调用no-args构造函数(java.lang.NoSuchMethodException:br.edu.ufca.criacaoemail.ViewParamValidationFailed。())。
任何想法我该如何解决这个问题?
谢谢。