1
votes

If I want to use an XPage as subform, and I use the IncludePage control, I don't know how to define a datasource or bind fields to the single datasource of the main XPage.

It's easy to have the embedded Xpage have its own separate datasource and then write to fields on a separate document, but how do I simply save the value of fields to the current document when I take an action/click the submit button? (i.e. I'm not using multiple datasources)

This is the code on the Main xpage:

<xp:include pageName="/P1.xsp" id="include2">
</xp:include>

On the P1 xpage I just don't know how to define the datasource the same (document1).

2

2 Answers

0
votes

You can do what you want: including an XPages in another. That works fine.

Think of an included page like the content of this page would be written direct inside the main page. So, you can just use document1 like

value="#{document1.myOtherField}"

to bind a form field to main page's document1 item.

BUT, you can't change the included page in include control without reloading the main page. That means, this approach won't work for you according to your comment:

What I am trying to do is have the user answer a series of questions. So, they'll answer one, click "Next Page", answer the next, etc. It would save/update the document each time. I thought it would be easiest to use xpages as subforms and pull up the "main" xpage (document1) with next/appropriate xpages now visible.

Instead, create panels each containing a subset of your questions. Add rendered-conditions to the panels based on a viewScope variable, change this viewScope variable when user clicks next/previous button and partially refresh those panels. This way only one panel at a time is visible and you don't need to save the document every time.

0
votes

Is there a reason for not using a Custom Control? If you want all that content on its own page, just create an XPage and put only the custom control on there. If you want it with additional content, create a different XPage with the additional content as well as the custom control.

With custom controls, you can access a datasource that's at a higher level of the hierarchy, so access an XPage's datasource from a custom control on that XPage. You don't get the typeahead, but it's perfectly valid to use. So in this case you'd have the document1 datasource on the XPages, and just use document1.myField or document1.save() on the custom control.

It might also work with an IncludePage control. I'm not sure if an IncludePage works basically the same as a Custom Control in how it adds it to the containing XPage.