Java EE 8下的注入失败 - 在FacesValidator中

问题描述 投票:0回答:1

我们在服务器calsses中使用GenericValidator。实现通过RequestScoped Managed bean注入。当我们在Java EE 7(Wildfly 13)下运行这个例子时,everthing工作正常。现在我们尝试迁移到Java EE 8(Under Wildfly 14下)。不知何故,我们现在得到一个NullPointerException。我该如何摆脱错误?

Snipped:

password.xhtml

<p:password id="password"  widgetVar="#{cc.clientId}"
    value="#{cc.attrs.compBean.componentData[cc.clientId].value}">
    <f:validator for="password" validatorId="genericValidator" />
</p:password>

generic validator.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)

  }
...
}

validate.Java

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)
jsf wildfly cdi java-ee-8
1个回答
2
投票

我们不得不将Omnifaces版本从2.6升级到3.2。这是必要的,因为使用Java EE 8从JSF 2.2升级到2.3。

© www.soinside.com 2019 - 2024. All rights reserved.