0
votes

What is the best way to bind a non-managed bean to an xPage? We use xPages controller classes in java, and would like to limit some classes to a specific xPage without using managed bean in faces-config.

Tried to use dataContext and some of the methods work, but we are not able to get the document data source, using resolveVariable method. It always returns doc=null. The same java class as a managed bean returns the data source correct.

Are there better ways to connect a bean to a specific xPage?

1
Sorry for asking, but is there any reason for doing it this way? What are the benefits?Sven Hasselbach
When you used a dataContext, what was the scope of the dataContext and what was the scope of the dominoDocument datasource? Just as a managed bean is scoped to view, session etc, a dominoDocument datasource and a dataContext can be scoped to the XPage, a Custom Control, a Panel etc. Depending on the scope, the problem may just be that one is not visible to the other.Paul Stephen Withers
I use a ViewHandler to store a new controller instance in the viewScope when each page is constructed, so all events can just be bound to #{viewScope.controller.someMethodName} regardless of which page it is, because the logic for determining which controller class to use is bundled within the ViewHandler. Let me know if this sounds like a viable approach for you, and I'll provide a detailed answer showing how this all fits together.Tim Tripcony
#Sven: The reason we wanted to do this is that we are working on a portal with many xPages and databases involved, and we wanted to limit some of the logic to specific xPages. Do not know if there is a limit to faces-config size, but felt it became very loaded if everything needed to go in there. . .Fred

1 Answers

2
votes

You can connect your Java controller with an XPage in beforePageLoad event:

    <xp:this.beforePageLoad><![CDATA[#{javascript:
        viewScope.controller = new com.yourdomain.controller.MyController();
        controller.beforePageLoad()}]]>
    </xp:this.beforePageLoad>

Then you can call methods of your controller using EL like this:

#{controller.save}

or you can connect certain events with your controller:

<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
    afterPageLoad="#{controller.afterPageLoad}"

Your controller has access to document data source.

    public void save() throws Exception {
        DominoDocument doc = (DominoDocument) JsfUtil.resolveVariable("currentDocument");
        System.out.println("save(" + doc.getDocument().getUniversalID() + ")");
    }