简体   繁体   English

错误渲染视图 [/login.xhtml]: java.lang.NullPointerException 在启动服务器 PF10

[英]Error Rendering View[/login.xhtml]: java.lang.NullPointerException on starting server PF10

Environment:环境:

  • wildfly 22野蝇 22
  • java 11 java 11
  • jakarta 8雅加达 8
  • jsf 2.3 jsf 2.3
  • primefaces 10 primefaces 10

Migrating from Primefaces 6.2 to 10.从 Primefaces 6.2 迁移到 10。

I am having a NPE on loading server with an app, and on render login.xhtml it throws java.lang.NullPoinerException.我在使用应用程序加载服务器时有一个 NPE,在渲染 login.xhtml 时它会抛出 java.lang.NullPoinerException。 I found no clue on error log.我在错误日志中找不到任何线索。 Any idea where the problem is?知道问题出在哪里吗?

login.xhtml登录.xhtml

<!DOCTYPE html>
<html lang="#{localeBean.locale}"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui">
<h:head>
    <title>#{msgs.appcode}</title>
</h:head>

<h:body>
    <h:form id="frmLogin">
        <p:inputText id="j_username" placeholder="#{msgs.user}"
                     value="#{loginBean.username}"
                     autocomplete="off">
        </p:inputText>
        <p:inputText id="j_password" type="password"
                     placeholder="#{msgs.password}"
                     value="#{loginBean.password}"
                     autocomplete="off"
                     converter="charArrayConverter"/>
        <p:commandButton id="btnButton"
                         value="#{msgs.login}"
                         action="#{loginBean.login}"/>
    </h:form>
</h:body>
</html>

LoginBean.java登录Bean.java

@Named("loginBean")
@RequestScoped
public class LoginBean implements Serializable {

    private static final long serialVersionUID = 1689411186706761477L;

    @Inject
    Logger logger;

    @Inject
    private HttpServletRequest request;

    private String username;
    private char[] password;
    private Messages msgs;

    @Inject
    @ManagedProperty(value = "#{sessionBean}")
    private SessionBean sessionBean;

    public LoginBean() {
    }

    @PostConstruct
    private void init() {
        logger.info("loginBean");
    }

    public void login() {
        try {
            if (request.getUserPrincipal() == null) {
                request.login(username, String.valueOf(password));
            }
        } catch (ServletException ex) {
            logger.error("Error login failed", ex);
            navigate(Pages.LOGINERROR.getPage());
            return;
        }
        navigate(Pages.INDEX.getPage());
    }
...

Error log错误日志

21:36:43,292 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (default task-1) Error Rendering View[/login.xhtml]: java.lang.NullPointerException
    at com.sun.jsf-impl@2.3.14.SP02//com.sun.faces.cdi.ManagedPropertyProducer.evaluateExpressionGet(ManagedPropertyProducer.java:87)
    at com.sun.jsf-impl@2.3.14.SP02//com.sun.faces.cdi.ManagedPropertyProducer.lambda$new$0(ManagedPropertyProducer.java:60)
    at com.sun.jsf-impl@2.3.14.SP02//com.sun.faces.cdi.CdiProducer.create(CdiProducer.java:105)
    at com.sun.jsf-impl@2.3.14.SP02//com.sun.faces.cdi.ManagedPropertyProducer.create(ManagedPropertyProducer.java:38)
    at org.jboss.weld.core@3.1.5.Final//org.jboss.weld.contexts.unbound.DependentContextImpl.get(DependentContextImpl.java:64)
    at org.jboss.weld.core@3.1.5.Final//org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:100)
    at org.jboss.weld.core@3.1.5.Final//org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
    at org.jboss.weld.core@3.1.5.Final//org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:694)
    at org.jboss.weld.core@3.1.5.Final//org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:794)
    at org.jboss.weld.core@3.1.5.Final//org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:92)
    at org.jboss.weld.core@3.1.5.Final//org.jboss.weld.util.Beans.injectBoundFields(Beans.java:336)
    at org.jboss.weld.core@3.1.5.Final//org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:347)
...
21:36:43,298 ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to /app/login.xhtml: java.lang.RuntimeException: javax.servlet.ServletException
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.security.ServletFormAuthenticationMechanism.servePage(ServletFormAuthenticationMechanism.java:172)
    at io.undertow.core@2.2.4.Final//io.undertow.security.impl.FormAuthenticationMechanism.sendChallenge(FormAuthenticationMechanism.java:183)
    at io.undertow.core@2.2.4.Final//io.undertow.security.impl.SecurityContextImpl$ChallengeSender.transition(SecurityContextImpl.java:301)
    at io.undertow.core@2.2.4.Final//io.undertow.security.impl.SecurityContextImpl$ChallengeSender.transition(SecurityContextImpl.java:319)
    at io.undertow.core@2.2.4.Final//io.undertow.security.impl.SecurityContextImpl$ChallengeSender.access$300(SecurityContextImpl.java:284)
...
Caused by: javax.servlet.ServletException
    at javax.faces.api@3.0.0.SP04//javax.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:725)
    at javax.faces.api@3.0.0.SP04//javax.faces.webapp.FacesServlet.service(FacesServlet.java:451)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:81)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    at io.undertow.core@2.2.4.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)
    at io.undertow.core@2.2.4.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.core@2.2.4.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:251)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.ServletInitialHandler.dispatchToPath(ServletInitialHandler.java:186)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.spec.RequestDispatcherImpl.forwardImpl(RequestDispatcherImpl.java:227)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.spec.RequestDispatcherImpl.forwardImplSetup(RequestDispatcherImpl.java:149)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.spec.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:111)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.security.ServletFormAuthenticationMechanism.servePage(ServletFormAuthenticationMechanism.java:170)
    ... 48 more
Caused by: java.lang.NullPointerException
    at com.sun.jsf-impl@2.3.14.SP02//com.sun.faces.cdi.ManagedPropertyProducer.evaluateExpressionGet(ManagedPropertyProducer.java:87)
    at com.sun.jsf-impl@2.3.14.SP02//com.sun.faces.cdi.ManagedPropertyProducer.lambda$new$0(ManagedPropertyProducer.java:60)
    at com.sun.jsf-impl@2.3.14.SP02//com.sun.faces.cdi.CdiProducer.create(CdiProducer.java:105)
    at com.sun.jsf-impl@2.3.14.SP02//com.sun.faces.cdi.ManagedPropertyProducer.create(ManagedPropertyProducer.java:38)
    at org.jboss.weld.core@3.1.5.Final//org.jboss.weld.contexts.unbound.DependentContextImpl.get(DependentContextImpl.java:64)

Error on Context path with explorer资源管理器的上下文路径错误

Context Path:
/app

Servlet Path:
/index.xhtml

Path Info:
null

Query String:
null

Stack Trace:

javax.servlet.ServletException
    at javax.faces.api@3.0.0.SP04//javax.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:725)
    at javax.faces.api@3.0.0.SP04//javax.faces.webapp.FacesServlet.service(FacesServlet.java:451)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
    at io.undertow.websocket@2.2.4.Final//io.undertow.websockets.jsr.JsrWebSocketFilter.doFilter(JsrWebSocketFilter.java:173)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at io.opentracing.contrib.opentracing-jaxrs2//io.opentracing.contrib.jaxrs2.server.SpanFinishingFilter.doFilter(SpanFinishingFilter.java:52)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at deployment.app.war//es.app.light.business.security.boundary.WebAuthenticator.doFilter(WebAuthenticator.java:81)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    at org.wildfly.extension.undertow@22.0.1.Final//org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.core@2.2.4.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:117)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
    at io.undertow.core@2.2.4.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.core@2.2.4.Final//io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:53)
    at io.undertow.core@2.2.4.Final//io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:59)
    at io.undertow.core@2.2.4.Final//io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
    at io.undertow.core@2.2.4.Final//io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
    at io.undertow.core@2.2.4.Final//io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
    at io.undertow.core@2.2.4.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at org.wildfly.extension.undertow@22.0.1.Final//org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.core@2.2.4.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at org.wildfly.extension.undertow@22.0.1.Final//org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.SendErrorPageHandler.handleRequest(SendErrorPageHandler.java:52)
    at io.undertow.core@2.2.4.Final//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:269)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:78)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:133)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:130)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
    at org.wildfly.extension.undertow@22.0.1.Final//org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
    at org.wildfly.extension.undertow@22.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
    at org.wildfly.extension.undertow@22.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
    at org.wildfly.extension.undertow@22.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
    at org.wildfly.extension.undertow@22.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
    at org.wildfly.extension.undertow@22.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:249)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:78)
    at io.undertow.servlet@2.2.4.Final//io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:99)
    at io.undertow.core@2.2.4.Final//io.undertow.server.Connectors.executeRootHandler(Connectors.java:387)
    at io.undertow.core@2.2.4.Final//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:841)
    at org.jboss.threads@2.4.0.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
    at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
    at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
    at org.jboss.xnio@3.8.4.Final//org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1280)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NullPointerException
    at com.sun.jsf-impl@2.3.14.SP02//com.sun.faces.cdi.ManagedPropertyProducer.evaluateExpressionGet(ManagedPropertyProducer.java:87)
    at com.sun.jsf-impl@2.3.14.SP02//com.sun.faces.cdi.ManagedPropertyProducer.lambda$new$0(ManagedPropertyProducer.java:60)
    at com.sun.jsf-impl@2.3.14.SP02//com.sun.faces.cdi.CdiProducer.create(CdiProducer.java:105)
    at com.sun.jsf-impl@2.3.14.SP02//com.sun.faces.cdi.ManagedPropertyProducer.create(ManagedPropertyProducer.java:38)
    at org.jboss.weld.core@3.1.5.Final//org.jboss.weld.contexts.unbound.DependentContextImpl.get(DependentContextImpl.java:64)

SessionBean.java SessionBean.java

@Named
@SessionScoped
public class SessionBean implements Serializable {

    ...

    private Logger logger;

    @Inject
    private UserProvider userPdr;
    
    @Inject
    @ManagedProperty(value = "#{localeBean}")
    private LocaleBean localeB;

    ...

    private User user;

    public SessionBean() {
        logger = LoggerFactory.getLogger(this.getClass());
    }

    @PostConstruct
    private void init() {
        try {
            dealWithSession();
            
            if(user == null) {
                user = getUser();
            }
        } catch (Exception e) {
            logger.error("Exception init {0}", e.getMessage());
        }
    }
...

LocaleBean.java LocaleBean.java

@Named
@SessionScoped
public class LocaleBean implements Serializable {

    private static final long serialVersionUID = 1511093313205693034L;

    private Locale locale;
    private final List<Locale> locales = new ArrayList<>();

    Logger logger;
    
    @PostConstruct
    public void init() {
        logger = LoggerFactory.getLogger(this.getClass());

        try {
            locales.add(new Locale("es", "ES"));
            locales.add(new Locale("ca", "ES"));

            Locale userLocale = FacesContext.getCurrentInstance().getExternalContext().getRequestLocale();
            if (locales.contains(userLocale)) {
                locale = locales.get(locales.indexOf(userLocale));
            } else {
                locale = locales.get(0);
            }
        } catch (Exception e) {
            logger.error("Exception: {0}", e.getMessage());
        }
    }
...

It was a custom theme incompatibility with pu:menu and p:menu in PF10 so I had to update theme to a PF10 compatible version.这是与 PF10 中的 pu:menu 和 p:menu 的自定义主题不兼容,因此我不得不将主题更新为 PF10 兼容版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.NullPointerException 尝试使用 JSF、Primefaces 3.5 和 Glassfish 3.2 渲染视图 ShoppingCart.xhtml 时。 - java.lang.NullPointerException when trying to rendering view ShoppingCart.xhtml with JSF, Primefaces 3.5 and Glassfish 3.1.2.2 错误:在ExternalContext中找不到/login.xhtml作为资源 - Error: /login.xhtml Not Found in ExternalContext as a Resource login.xhtml:请求的资源不可用 - login.xhtml: The requested resource is not available 错误呈现视图[/index.xhtml] java.lang.NumberFormatException:对于输入字符串:“” - Error Rendering View[/index.xhtml] java.lang.NumberFormatException: For input string: "" javax.faces.el.E​​valuationException:java.lang.NullPointerException错误 - javax.faces.el.EvaluationException: java.lang.NullPointerException error 错误呈现视图[.xhtml] - Error Rendering View [.xhtml] * .xhtml url-pattern导致com.sun.faces.context.flash.ELFlash.loggingGetPhaseMapForReading中的java.lang.NullPointerException - *.xhtml url-pattern causes java.lang.NullPointerException at com.sun.faces.context.flash.ELFlash.loggingGetPhaseMapForReading Primefaces终端导致java.lang.NullPointerException - Primefaces terminal causes java.lang.NullPointerException java.lang.NullPointerException selectOneMenu转换器 - java.lang.NullPointerException selectOneMenu convertor 春季注入java.lang.NullPointerException - spring injection java.lang.NullPointerException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM