xpagesbeast
xpagesbeast

Reputation: 816

How can I get a handle to DataSource (document1) from a Java Bean

How can I get a handle to a DataSource on a XPages from a Java Bean and call its Save() method?

The default variable (ID) is 'document1'.

In ServerSide JavaScript, its a variable document1.save(); //pretty simple.

However, in JSF, I think I have to use the component tree facesContext to get a handle to it.

Thoughts?

Upvotes: 1

Views: 289

Answers (1)

Eric McCormick
Eric McCormick

Reputation: 2733

document1 is a handle to a "NotesXspDocument" (in Domino's SSJS), the specific Java class being com.ibm.xsp.model.domino.wrapped.DominoDocument. The easiest way to get a handle on such a defined document1, without passing a reference handle via parameter to a method, would be to resolve the variable.

You can use the Extension Library's ExtLibUtil method of resolveVariable(String name), pre- 9.0.1_v15 this required a second parameter of the FacesContext instance; resolveVariable(FacesContext ctx, String name).

Alternatively, you could skip the ExtLibUtil entirely, although I much prefer it and use it regularly, with the following:

DominoDocument myDoc = (DominoDocument) FacesContext.getCurrentInstance()
    .getApplication().getVariableResolver()
    .resolveVariable(FacesContext.getCurrentInstance(), "document1");

As you can see from the fact that we're resolving the variable, via the user's FacesContext instance, document1 must actually exist/be accessible to the given FacesContext instance for this to work. The ExtLibUtil method(s) both are wrappers to the FacesContext variable resolver.

Upvotes: 6

Related Questions