This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Aug 2, 2011, 6:57 AM
8 Posts

Issues with multiple instances of a custom control

  • Category: Debugging
  • Platform: Windows
  • Release: 8.5.2
  • Role: Developer
  • Tags: custom control,component,id
  • Replies: 6
I have a custom control, that I would like to use in at least two places in a single view (basically the same controll underneath two tabs of a tabbed panel). I have a field in this custom control where I would like to set a current value of a view scope variable whenever the fiel is shown. By the nature of two separate areas the values, of course, should differ depending on which tab I'm currently looking. While the view scope variables work fine I noticed that I have a problem with the target id in which field the value should show up in. To clarify the point I am trying to make, here's a (heavily WIP) screenshot:
 
 
The first red panel shows the value in the view scope variable "INTENDED_TARGET". This is client id of the component I get during the beforeRenderResponse phase of my custom control. The second red panel to the bottom end of the screenshot shows the actual id of the component that it would need to go to. The code behind the two is identical (except for the bit in the beforeRenderResponse where I put it in a viewscope variable). Both times I used getComponent("value1").getClientId(facesContext). What do I have to do to get the correct component of the correct instance of my custom control? Any help is greatly appreciated.
 
 
Aug 2, 2011, 8:33 AM
33 Posts
Re: Issues with multiple instances of a custom control
So if I understand it correctly you have one CC on every tab and on its beforeRenderResponse event you store client id of one of its fields to the viewScope.
And you do that because you want to set some value to that field. 
When and how exactly you want to do that? I'm not aware of any situation that would require such a complicated solution.
Aug 2, 2011, 9:03 AM
8 Posts
Re: Issues with multiple instances of a custom control
Hello Stepan,
 
thanks for your reply. My custom control is actually a nested one. What I am trying to achieve is being able to have a TextArea to edit a multivalue field in a Domino document. TextArea because the entries in the field are going to contain formulas that might be long and complex. I have several fields on my data source that I would like to fill this way. The custom control has a repeat element that shows the currently entered values and some icons to edit and delete entries. When clicking the pencil icon to the right of an item, the TextArea is made visible to edit the content of the selected entry. To show the current value of the selected entry I use the beforeRenderResponse event of the nested editor custom control (which mainly consists of spoken TextArea) to fill the TextArea with spoken entry value. This works fine for my "Conditions" tab, not so much for my "Creation" tab, where the exact same control is used a second time. With this second instance, when I try to get the component in the nested control, it places the value in the field of the first instance (the Conditions Panel).
 
I have prepared another screenshot to show the open text area with the last list value being the currently selected on (clicked on the pencil next to it):
 
As pointed out, everything works fine on the "Conditions" tab, however the methdo getComponent("value1") hands back the field of the tab "Conditions" no matter what instance of the custom control the request is coming from. Hope that clears up a little what I am trying to do.
Aug 2, 2011, 9:53 AM
33 Posts
Re: Issues with multiple instances of a custom control
So you have custom control A which lists all entries in multi-value field. And custom control B which is nested in CC A and contains a text area editor.
My question is: Do you use CC B on other places? 
Because if you don't then I don't see a reason not to include content of CC B in CC A.
If you want to keep CC A and CC B then you should consider different approach.
Maybe create client side javascript API to work with CC B.
 
Then you would use something like this as the pencil button handler: 
 
var ccbApi = new CCBAPI('clientID of CCB');
var textArea = ccbApi.getTextAreaObject();
textArea.innerHTML = 'formula';
 
The getTextAreaObject method would use dojo.query() to find the textarea within html of CCB.
 
Hope this helps 
Aug 2, 2011, 10:09 AM
8 Posts
Re: Issues with multiple instances of a custom control
Unfortunately, reducing the levels of nested custom controls does not help. I have created a very simple example database that shows the problem. I have a single custom component, containing two labels. Each of these labels is supposed to show the clientside id of the field in the control. On is filled via the beforeRenderResponse, one has a directly computed label value. The latter works in both instances, the first one works only in the first instance and shows the first instances cliendid in the second instance.
 
Here is the link to the basic example:
http://www.mediafire.com/?onlfaur56sw01bo
 
(sorry, link dialog says it's invalid, but in fact it's not, another story ...)
 
There is only a single page in there containing two instances of the same, not nested custom control.
 
You may find the output of the xpage here:
http://www.dev.pitagora.at/xspprobl.nsf/someXPage.xsp 
Aug 3, 2011, 8:27 AM
33 Posts
Re: Issues with multiple instances of a custom control
First problem is that beforeRenderResponse events for all components occur before calling code to get the value of a label.
So if you put some print statements inside the brr event and inside the value property of a label you will see something like this:
 
brr event 
brr event
get value 
get value 
 
which makes your approach unusable. 
Second problem is that in my opinion the code in brr event is run in context of containing xpage so it grabs first component with id 'someField' it finds.
And that is always the same. 
 
As I wrote before if you want to work with components on client side make sure you have all of them in one CC or make some client side API. 
 
EDIT:  If you have all components in one CC then there is no reason to use viewscope to store their ids
Aug 3, 2011, 8:21 PM
8 Posts
Re: Issues with multiple instances of a custom control
It might be me who is wrong, probably so. However I am only using viewscope variables to fetch the value of the clientside id to have it later display on the page for debugging purposes. Since the view scope variable does show the client id, to me that suggests it is there during the phase the beforeRenderResponse event is triggered. It is even there before the first instance of someField is rendered on the page. However, it stays the same for the second instance and that behaviour makes no sense to me. It seems very much like a bug. Either there should be no value available for a client id during beforeRenderResponse, or the actual value of the relevant client id relative to the instance the component is located on.
 
All I want to do is to set the value of a field during the beforeRenderResponse event is handled. I consider this to be not such a far off approach. As said, the viewScope variable were only involved to see the actual client ids and make them visible on the front end. In production, it should work without client ids in viewScope variable. By no means am I trying to do something on the client.

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal