问题
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?
Appreciating any suggestions/advices!
回答1:
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;
}
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.
来源:https://stackoverflow.com/questions/40635829/binding-a-xpage-dominodocument-to-a-bean