我们在服务器calss中使用一个泛型验证器。实现是通过RequestScoped托管bean注入的。当我们在JavaEE 7(Wildfly 13)下运行这个例子时,EvWork工作得很好。现在我们尝试迁移到JavaEE 8(Under Wildfly 14)。不知何故,我们现在得到一个空指针异常。
我怎样才能消除这个错误?
在这里被剪下的:
XHTML
value="#{cc.attrs.compBean.componentData[cc.clientId].value}">
GenericValidator.java
...
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
import javax.inject.Inject;
@FacesValidator("genericValidator")
public class GenericValidator implements Validator, ClientValidator, Serializable {
...
@Inject
private Validate validator;
@Override
public void validate(FacesContext fc, UIComponent uic, Object value) throws ValidatorException {
validator.validate(fc, uic, value); // Here is the NullPointer (validator is null)
}
...
}
验证程序
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;
import javax.inject.Inject;
import javax.inject.Named;
import org.omnifaces.util.Ajax;
@Named
@RequestScoped
public class Validate implements Serializable {
...
}
堆栈跟踪
SEVERE [org.omnifaces.exceptionhandler.FullAjaxExceptionHandler] (default task-5) FullAjaxExceptionHandler: An exception occurred during processing JSF ajax request. Error page '/errorpage.xhtml' will be shown.: java.lang.NullPointerException
at COMPANY.client.ui.validation.GenericValidator.validate(GenericValidator.java:32)
at javax.faces.component.UIInput.validateValue(UIInput.java:1248)
at javax.faces.component.UIInput.validate(UIInput.java:1037)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1334)
at javax.faces.component.UIInput.processValidators(UIInput.java:757)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:632)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1736)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1747)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1747)
at javax.faces.component.UINamingContainer.visitTree(UINamingContainer.java:177)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1747)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1747)
at javax.faces.component.UIForm.visitTree(UIForm.java:395)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1747)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1747)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1747)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1747)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1747)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1747)
at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:424)
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:285)
at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:57)
at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:252)
at org.omnifaces.context.OmniPartialViewContext.processPartial(OmniPartialViewContext.java:124)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1330)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:77)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:201)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:670)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
at io.undertow.websockets.jsr.JsrWebSocketFilter.doFilter(JsrWebSocketFilter.java:173)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at COMPANY.client.common.filter.LogFilter.doFilter(LogFilter.java:52)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at COMPANY.client.ui.filter.AuthenticationFilter.doFilter(AuthenticationFilter.java:166)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at org.omnifaces.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:124)
at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:108)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)