本文介绍了将Xpage DominoDocument绑定到Bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将DominoDocument直接绑定到托管Bean.这样我就可以在Bean中拥有一个属性,该属性始终保持对DominoDocument的引用?

is it possible to bind a DominoDocument directly to a Managed Bean. So that I can have a property in my Bean which holds a reference to the DominoDocument all the time?

赞赏任何建议/建议!

推荐答案

如上所述,最简单的方法是将其绑定到bean中的属性,而不是将其绑定到bean中的属性,而只需在您的bean中使用方法即可豆.

As Per mentioned above, the simplest way to do what you want is instead of binding it to a property in your bean, just access it using a method in your bean.

public DominoDocument getDominoDocument() {

    // Whatever the data source name is you want to get
    String documentName = "document1";  

    Object o = ExtLibUtil.resolveVariable(FacesContext.getCurrentInstance(), documentName);

    // Double check that it is a DominoDocument
    if (o instanceof DominoDocument) {
        return (DominoDocument) o;
    }

    return null;

}

如果您无法使用扩展库,请使用:

If you are unable to use the Extension Library, then use:

public DominoDocument getDominoDocument() {

    // Whatever the data source name is you want to get
    String documentName = "document1";  

    // Get the VariableResolver for Current FacesContext and Resolve the variable
    FacesContext facesContext = FacesContext.getCurrentInstance();
    VariableResolver resolver = facesContext.getApplication().getVariableResolver();
    Object o = resolver.resolveVariable(facesContext, documentName);

    // Double check that it is a DominoDocument
    if (o instanceof DominoDocument) {
        return (DominoDocument) o;
    }

    return null;

}

数据源在请求之间使用对托管Bean的持久性稍有不同的机制进行持久化,因此,如果将数据源绑定到托管Bean属性,则可能会出现复杂性,具体取决于应用程序在哪种持久性模式下运行尽管我不确定,但可能还可以.另外,还有一个复杂的DataSource<-> DataContainer<-> DominoDocument生态系统,变量解析器知道如何处理,因此最简单的方法就是在访问变量解析器时对其进行访问.

Data Sources are persisted between requests using a slightly different mechanism to persistence of managed beans, so if you bind a Data Source to a managed bean property, there might possibly be complications depending on what sort of persistence mode an application is running in. It might be okay though I am not sure. Also there is a complicated DataSource <-> DataContainer <-> DominoDocument ecosystem which the variable resolver knows how to deal with, so it is simplest to just go through the variable resolver when you want to access it.

这篇关于将Xpage DominoDocument绑定到Bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:42