PermaLink XPages: The View article(s) - How to Compute a Custom Control at Runtime09/13/2009 10:40 AM
Domino 8.5
I recently had 2 articles published in The View that demonstrate how to compute which custom control to display at runtime based on a formula.  This is similar to using a computed subform in traditional Notes/Domino development.  

The first article provides the technical overview on how to accomplish this using a built-in XPages feature.  The second article expands on the first by enhancing the custom control to allow the use of parameters so that it can be re-used in any of your applications.

Here's a synopsis of the articles.  (the full articles require a subscription login)

XPages — How to Compute a Custom Control at Runtime
     
       
When Domino developers first start exploring XPages, they naturally tend to compare the new XPages controls and functionality with traditional IBM Lotus Notes and Domino development: “I know what I want to do and how I would have accomplished it with Domino Designer. Now how do I do it in XPages?”

Take the concept of a Notes computed subform. I have heard many developers asking how this is handled in XPages. While many Notes concepts are handled the same way in XPages as in traditional Notes development, the computed-subforms concept is not one of them.

The XPages design component that most closely corresponds with subforms is the custom control. You use a custom control where you have a group of fields or functionality that you want to reuse on other XPages within your application. Once created, a custom control shows up in the Controls palette. Then you can drag and drop the control onto any XPage in your application.

In Notes, you can compute which subform to include on a form based on a formula. Computing which subform to include at runtime is an easy way to tailor the form and functionality without having to maintain numerous hide/when formulas. This is a very valuable feature for rapid application development. With XPages, however, there is no computed custom control. I’ll show you a technique to help you get functionality in XPages that is similar to computed subforms.
 
XPages — A Reusable Solution for Computing a Custom Control at Runtime
In XPages development, you use a custom control when you have a group of fields or functionality that you want to reuse on other XPages within your application. In an earlier article (THE VIEW, 2009) I showed you how to use a custom control that computes which custom control to display on an XPage at runtime, similar to using computed subforms in Domino Designer.

Now I’ll show you how to enhance that custom control so you can reuse it in any XPages application to compute any custom control at runtime. Plus, I’ll show you how to create custom control properties for parameters that can be accessed with serverside JavaScript. Learning how to parameterize your custom controls will enable you to build your own library of reusable controls for rapid application development.

-John


Technorati:
This page has been accessed 3425 times. .
Comments :v

1. Vitalijs10/16/2009 09:26:52 AM


This is very simple technique.
1. create a repeater
2. put there include page control (<xp:include pageName='${javascript:"test_IncludeControl.xsp"}' id="include1"></xp:include>)
3. compute control name adding at the end .xsp

P.S. include page not ony can include pages, but also custom controls.




2. Judy05/12/2010 08:43:47 PM


I stumbled upon this while looking for something else in your blog, and the comment by Vitalijs is precisely the solution I was looking for to dynamically load a custom control. Thanks to the both of you! John, I am most grateful -- your blog & examples are an indispensable resource to learning & using XPages.




3. Pascal David02/02/2011 04:55:37 AM


Both approaches (computed facet name and computed include page) have one problem: you cannot change the custom control unless you completely reload the page.

For example, I want to display a different custom control in function of a dropdown box on the container XPage. Neither the facet name, nor the computed page name will be recomputed with a partial or a full update. What you need to do is reopen the web page by redirecting to the same url as the actual one.

Actually, the facet name will recompute dynamically, but in the computing script, you won't have access to the dropdown box. Even when using a viewScope or sessionScope variable, the facet calculation won't get the update of that variable, unless you re-open the page by redirecting.




4. Stacey04/15/2011 09:49:54 AM


Thanks Pascal! So in order to dynamically hide/show custom controls in an xpage you have to set the variable and reload the xpage with CSJS? Why do we need a repeat? Can anyone provide a sample?




Search
Partner with us
Need help on your XPages projects?

Talk to the experts! Read more...
XPage Examples
By Category
About Me
Downloads
My Links
Monthly Archive
Powered by
Blogsphere
Lotus Domino ND7 RSS News Feed RSS Comments Feed Geo URL netcraft RSS Validator Lotus Geek Chris. A. Brandlehner OpenNTF BlogSphere