繁体   English   中英

在WebSphere 9上的JSF 2.2中管理bean

[英]Managing beans in JSF 2.2 on WebSphere 9

发布此问题/答案,因为我没有找到其他任何非常相似的问题。 很多相关的,但情况不一样。

正在将JSF 2.1升级到JSF 2.2(Mojarra)应用程序以支持h:fileUpload。 应用程序在WebSphere 9上运行,升级后使用JSF Beans进行依赖项注入时遇到问题。

进一步阅读,我意识到JSF @ManagedBean已被弃用,应迁移到CDI @Named但是我们的应用程序有627个对FacesContext的引用,并且迁移到CDI bean意味着更新所有这些位置,以便在需要时生成FacesContext或将JSF升级到2.3,并在需要的地方注入FacesContext。 这意味着暂时使用JSF 2.2。

这是豆子:

package com.company.customersearch;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

@ManagedBean(name = "customerSearchManager")
@ViewScoped
public class customerSearchManager extends PortletManager{

    private static final long serialVersionUID = -9050481751306478727L;
    private Long customerId;
    private SessionData sessionData;

    @ManagedProperty(value = "#{customerSearchService}")
    private CustomerSearchService service;

    public CustomerSearchManager(){
        this.sessionData = new SessionData((HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false));
        if (sessionData.hasSelectedCustomer())
            this.customerId = sessionData.getData().getCustomerId();
    }   

...
}

在WebSphere 9上运行会产生NullPointerException

Error Rendering View[/pages/customer-search.xhtml]
                                 java.lang.NullPointerException
    at com.sun.faces.application.view.ViewScopedCDIEventFireHelperImpl.fireInitializedEvent(ViewScopedCDIEventFireHelperImpl.java:60)
    at com.sun.faces.application.view.ViewScopeContextManager.fireInitializedEvent(ViewScopeContextManager.java:394)
    at com.sun.faces.application.view.ViewScopeManager.processPostConstructViewMap(ViewScopeManager.java:312)
    at com.sun.faces.application.view.ViewScopeManager.processEvent(ViewScopeManager.java:244)
    at com.sun.faces.application.view.ViewScopeEventListener.processEvent(ViewScopeEventListener.java:68)

NPE即将脱离CDI相关课程! 当故意不使用CDI时,为什么在ViewScopedCDIEventFireHelperImpl.java获得NPE?

我不知道其他企业容器是否采用这种方式,但是对于WebSphere,默认情况下启用CDI,并且显然在运行时(??)覆盖或尝试替换JSF bean。 希望我对这种情况下容器中发生的事情有所了解。

在IBM网站上找到有关CDI设置的以下信息:

http://www-01.ibm.com/support/docview.wss?uid=swg21983564

如果确实打算使用JSF @ManagedBean并一起避免与CDI发生冲突,那么可以在JVM上设置两个属性。 为我工作。

设置:

com.ibm.ws.cdi.enableCDI = false
com.ibm.ws.cdi.enableImplicitBeanArchives  = false

希望它可以帮助某人。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM