Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 2 JSF2视图范围状态保存无法正确保存注入的属性和ejb_Jsf 2_Ejb_Websphere_View Scope_Managed Property - Fatal编程技术网

Jsf 2 JSF2视图范围状态保存无法正确保存注入的属性和ejb

Jsf 2 JSF2视图范围状态保存无法正确保存注入的属性和ejb,jsf-2,ejb,websphere,view-scope,managed-property,Jsf 2,Ejb,Websphere,View Scope,Managed Property,我目前正在使用WebSphere8.5和JSF2.0(MyFaces)。由于@ViewScoped bean的状态保存(服务器和客户端模式),我一直面临一些问题。我有下面的豆子 @ManagedBean @ViewScoped public class BrokenBean implements Serializable { //Problem: not synchronized with real SessionBean object @ManagedProperty(val

我目前正在使用WebSphere8.5和JSF2.0(MyFaces)。由于@ViewScoped bean的状态保存(服务器和客户端模式),我一直面临一些问题。我有下面的豆子

@ManagedBean
@ViewScoped
public class BrokenBean implements Serializable {

    //Problem: not synchronized with real SessionBean object
    @ManagedProperty(value="#{sessionBean})
    private SessionBean session;

    //Problem: this gives NotSerializableException to some server generated class.
    @EJB
    private MyEJB myejb;

    //Getter and Setter for above properties
}

@ManagedBean
@SessionScoped
public class SessionBean implements serializable{
    private Integer i;
    //Getter and Setter
}

//MyEJB has a method to get Counter from database
我的测试页面包含

<h:outputText value="#{brokenBean.session.i}"></h:outputText>
<h:outputText value="#{brokenBean.myejb.getCounter()}"></h:outputText>

从您的问题中可以看出,
{brokenBean.myejb.getCounter()}
应该被引用为
{brokenBean.myejb.counter()}
,因为您不需要为EL中的getter/setter方法指定前缀。@XtremeBiker哦,我不知道方法名“getCounter()”看起来像真正的“getter”。在我的测试应用程序中,我将一个数据库访问方法命名为“getCounter()”,但实际上没有名为counter的属性,所以我认为应该将它放在那里。
@ManagedBean
@ViewScoped
public class FixedBrokenBean implements Serializable {

    private transient SessionBean session;

    private transient MyEJB myejb;

    //I must use getters below when I access these two properties within this class
    //so that getters will perform a lookup if they are null at the time I need them.

    public MyEJB getMyejb() {
        if (myejb == null) {
            try {
                InitialContext ic = new InitialContext();
                myejb = (MyEJB) ic.lookup("java:global/testear/testejb/MyEJB !test.MyEJB");
            } catch (NamingException e) {
                e.printStackTrace();
            }
        }
        return myejb;
    }

    public SessionBean getSession() {
        if (session == null) {
            FacesContext context = FacesContext.getCurrentInstance();
            session = (SessionBean) context.getApplication().evaluateExpressionGet(context, "#{sessionBean}", SessionBean.class);
        }
        return session;
    }
}