XPages Tip: Reading Custom Properties and Modifying a Component Before a Page Loads

If you need to read a property on a custom control and do something to any component on the page before a page loads, it can get tricky because the compositeData object is not available in the beforeRenderResponse event and getComponent() does not work in the beforePageLoad event.

I have an application where I need to dynamically inject components before a page loads. However, the injection depends on custom properties on a custom control, so it needs to read the properties and then get a handle to a component and modify it. Since the compositeData object isn’t available in the beforeRenderResponse event and getComponent() doesn’t work in the beforePageLoad event, there’s no single place to put the code that I need.

Fortunately, there’s a simple workaround. Code in the beforePageLoad event can read custom properties from the compositeData object and store them in viewScope variables. Then, code in the beforeRenderResponse event can read those values from viewScope and use getComponent() to get the handle to the component that I need to modify.

Advertisements

5 responses to “XPages Tip: Reading Custom Properties and Modifying a Component Before a Page Loads”

  1. Donjay Harrington says :

    “I have an application where I need to dynamically inject components before a page loads.”

    SORRY for the stupid question, what type of components ?

    • Brad Balassaitis says :

      Custom fields defined dynamically in configuration documents. Admins of each instance can define field type, validation, rendered logic, combo box choices, etc. The options vary from instance to instance, so we needed a flexible way to inject fields and bind them to the form.

  2. Andrew Grabovetsky says :

    You also may checkout the solution discussed here: http://stackoverflow.com/questions/23884382/calculate-the-rendering-of-a-custom-control
    Would you need additional comments on this – feel free to contact me!

    • Brad Balassaitis says :

      What I’m doing is similar to Sven’s solution, except that the fields aren’t known ahead of time for each instance, so each field is injected dynamically as needed. It’s an awesome feature of XPages!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: