David Navarre
David Navarre

Reputation: 1022

Can you compute which custom control to use?

Think "computed subform", but in Xpages.

On one of my custom controls, depending on a certain value, I want to either present a custom control that renders a drop-down list using a combobox or renders an input box with a type-ahead.

This is on a custom control that renders a view, with all view configuration choices handled by a document rather than design, so several different views utilize the same custom control.

For example: I have a By Status view using the custom control that has status as the first column and we use a combobox to allow the user to select which Status value to filter by. Another view is sorted by Requisition number and I want to use a type-ahead instead of the combobox.

My preference is to use the same dynamic view custom control for both and have a formula that determines which of the two (comboBox or inputText) to use. How do I compute which custom control to load?

(Credit for the dynamic view control goes to Scott Good's folks over at Teamworks Solutions.)

Upvotes: 0

Views: 777

Answers (2)

Naveen
Naveen

Reputation: 6936

Some time back I saw this question on StackOverflow where the author had used Include Page control (xp:include) to include custom controls using pageName attribute based on formula.

<xp:include>
     <xp:this.pageName><![CDATA[${javascript:sessionScope.ccPageName + ".xsp";}]]> </xp:this.pageName>
</xp:include>

Similar to the technique described by Paul Withers in his answer the attribute of pageName is also computed on page load.

Upvotes: 1

Paul Stephen Withers
Paul Stephen Withers

Reputation: 15739

During it's life cycle, an XPage exists in two places. First of all a representation of the XPage's relevant components is stored on the server. Then the page goes through a lifecycle, retrieving properties from documents, checking which components should be rendered, retrieving the data for any repeating control such as a View Panel etc., and passing the relevant HTML to the browser. The browser is the second place it exists.

So you can't compute a custom control as such. All you can do is set the loaded property, and loaded needs to be based on a non-dynamic calculation such as a viewScope variable, the current XPage name, a view name stored on the XPage etc. What you would have difficulty doing would be using a different custom control based on data on that row entry.

The other option is the Dynamic Content control or Switch control from the Extension Library. Both are similar to using the loaded property, in that you're putting both custom controls on the page and choosing which to display.

From what you're describing, the loaded property should cover what you need.

Upvotes: 5

Related Questions