357 Lotus blogs updated hourly. Who will post next? Home | Downloads | Events | Pods | Blogs | Search | myPL | About 
 
Latest 7 Posts
Changing URL in File Download Control...
Wed, Jun 25th 2014 176
A Quick Question for Administrators...
Tue, Jun 10th 2014 233
RIP Tim Tripcony...
Mon, May 12th 2014 683
E-mail will be dead... For some people...
Sat, Feb 22nd 2014 359
IBM Connect 2014 slidedeck on the IBM Social Business Toolkit SDK
Thu, Feb 6th 2014 581
BP308 - The Journey to Becoming a Social Application Developer
Tue, Jan 21st 2014 249
My previous blog post was ’Hot’!
Sat, Dec 7th 2013 270
Top 10
RIP Tim Tripcony...
Mon, May 12th 2014 683
IBM Connect 2014 slidedeck on the IBM Social Business Toolkit SDK
Thu, Feb 6th 2014 581
Mystery Solved: "Error loading USE or USELSX module"
Mon, Nov 21st 2011 498
A little story about an error with ID Vault...
Wed, Jan 12th 2011 452
Authenticating Notes users for Web apps automatically...
Wed, May 11th 2011 378
E-mail will be dead... For some people...
Sat, Feb 22nd 2014 359
Still part of it: IBM Champions
Fri, Dec 6th 2013 289
My previous blog post was ’Hot’!
Sat, Dec 7th 2013 270
Domino is Curious: A Potential DAOS Problem...
Wed, Aug 14th 2013 250
BP308 - The Journey to Becoming a Social Application Developer
Tue, Jan 21st 2014 249


Multiple Custom Controls and Events aware of their owners...
Serdar Basegmez    

I am developing a simple (really simple) custom control for the OpenNTF contest... There are very good controls there and I don't think my humble control will be a revolutionary :)

Anyway, I really messed up this thing... Because I didn't plan the architecture right, I have to re-implement everything. The problem started when I tried using multiple copies of the same custom control.

This post will be a quick tip for a very simple problem. If you are developing a custom control which may be used more than once in the same XPage, you may bang your head like me...

Let's see a very simple case.

We have a simple Custom Control:

<?xml version="1.0" encoding="UTF-8"?> 
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

        <xp:listBox id="listBox1" value="#{viewScope.select}">
                <xp:selectItem itemLabel="Select1" itemValue="1"></xp:selectItem>
                <xp:selectItem itemLabel="Select2" itemValue="2"></xp:selectItem>
                <xp:selectItem itemLabel="Select3" itemValue="3"></xp:selectItem>
                <xp:eventHandler event="onchange" submit="true"
                        refreshMode="partial" refreshId="computedField1">
                </xp:eventHandler>
        </xp:listBox>
        <xp:text escape="true" id="computedField1" value="#{viewScope.select}"></xp:text>

</xp:view>


It's simple. We are selecting from a listbox and partial refresh will set the same value in the computed field. Let's use this twice in an XPage...

Image:Multiple Custom Controls and Events aware of their owners...

We select a value in the first control and it doesn't work. Let's select a value in the second one.

Image:Multiple Custom Controls and Events aware of their owners...

It seems OK. Now I am selecting the second option in the first control.

Image:Multiple Custom Controls and Events aware of their owners...

The problem is so obvious. We are using "viewScope.select" variable for both controls. So the solution is also obvious. We should use different variables for custom controls. This is a very common scheme, you define a property for the custom control (like uid) so you can refer different elements with different id's. I implemented the same scheme for this case.

<?xml version="1.0" encoding="UTF-8"?> 
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

        <xp:label id="label1"><xp:this.value><![CDATA[#{javascript:compositeData.uid+":"}]]></xp:this.value></xp:label>
        <xp:listBox id="listBox1">
                <xp:this.value><![CDATA[${javascript:"#{viewScope.select_"+compositeData.uid+"}"}]]></xp:this.value>
                <xp:selectItem itemLabel="Select1" itemValue="1"></xp:selectItem>
                <xp:selectItem itemLabel="Select2" itemValue="2"></xp:selectItem>
                <xp:selectItem itemLabel="Select3" itemValue="3"></xp:selectItem>
                <xp:eventHandler event="onchange" submit="true"
                        refreshMode="partial" refreshId="computedField1">
                </xp:eventHandler></xp:listBox>
        <xp:text escape="true" id="computedField1">
                <xp:this.value><![CDATA[${javascript:"#{viewScope.select_"+compositeData.uid+"}"}]]></xp:this.value>
        </xp:text>
</xp:view>


It works. Now we calculate which scope variable will be used...

However, if you look at the calculation, you may see the calculation starts with "${...", not with "#{...". That means the value mapping is calculated 'during the page loading' process... This is important. It is similar using 'calculated' field names. It cannot be changed in runtime.

Why is this so important?

Suppose you placed this custom control into a view control... Somehow, you have to set this "uid" parameter. "viewEntry.getPosition()" will be a good candidate. Or we can use "index" variable of the data source.

You cannot use these parameters in a view. Because, at the loading phase, view and its entries does not exist. If you are using repeat control, you may have a chance depending on your data source. But no chance with views.

<?xml version="1.0" encoding="UTF-8"?> 
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
        xmlns:xc="http://www.ibm.com/xsp/custom">
        <xp:viewPanel rows="30" id="viewPanel1">
                <xp:this.facets>
                        <xp:pager partialRefresh="true" layout="Previous Group Next"
                                xp:key="headerPager" id="pager1">
                        </xp:pager>
                </xp:this.facets>
                <xp:this.data>
                        <xp:dominoView var="view1" viewName="Contents"></xp:dominoView>
                </xp:this.data>
                <xp:viewColumn columnName="Title" id="viewColumn1">
                        <xp:viewColumnHeader value="Title" id="viewColumnHeader1"></xp:viewColumnHeader>
                </xp:viewColumn>
                <xp:viewColumn id="viewColumn2" value="">
                        <xp:this.facets>
                                <xp:viewColumnHeader xp:key="header"
                                        id="viewColumnHeader2">
                                </xp:viewColumnHeader>
                        </xp:this.facets>
                        <xc:CCTest03 uid="#{javascript:viewEntry.getPosition()}"></xc:CCTest03>
                </xp:viewColumn></xp:viewPanel>
</xp:view>


The result:
Image:Multiple Custom Controls and Events aware of their owners...

A quick workaround may be applied for limited number of cases.

Suppose we want to pass the selected value to a scope variable. If this is the only need, we have to find the selected value at onChange SSJS event. How are we going to find it?

By old habits, I tried "this.getValue()" in the event but it failed. So I just dumped the 'this' object inside the event and googled this class to find its super classes. I found it :)

We modify our custom control as the following:

<?xml version="1.0" encoding="UTF-8"?> 
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

        <xp:label id="label1"><xp:this.value><![CDATA[#{javascript:compositeData.uid+":"}]]></xp:this.value></xp:label>
        <xp:listBox id="listBox1">
                <xp:selectItem itemLabel="Select1" itemValue="1"></xp:selectItem>
                <xp:selectItem itemLabel="Select2" itemValue="2"></xp:selectItem>
                <xp:selectItem itemLabel="Select3" itemValue="3"></xp:selectItem>
                <xp:eventHandler event="onchange" submit="true"
                        refreshMode="partial" refreshId="computedField1">
                        <xp:this.action><![CDATA[#{javascript:viewScope.put("select_"+compositeData.uid, this.getParent().getValue())}]]></xp:this.action>
                </xp:eventHandler></xp:listBox>
        <xp:text escape="true" id="computedField1">
                <xp:this.value><![CDATA[#{javascript:viewScope.get("select_"+compositeData.uid)}]]></xp:this.value>
        </xp:text>
</xp:view>


You can see the added row there. "this" object is the event handler. Its parent gives us the component object and getValue() returns its value.

This notation can be used for many purposes. You may define generic functions in your library and any event calling those functions may pass its component into the function. I liked it :)


---------------------
http://lotusnotus.com/lotusnotus_en.nsf/dx/multiple-custom-controls-and-events-aware-of-their-owners....htm
Jun 16, 2011
103 hits



Recent Blog Posts
176


Changing URL in File Download Control...
Wed, Jun 25th 2014 7:11a   Serdar Basegmez
After a very long period of silence, here I am with a tiny little trick about File Download Control in XPages. I saw that there are lots of questions about this component, related to showing attachments instead of downloading them. Stephen Wissel explained how to build a download url with the XPages syntax. The old style notation (which DOES NOT work in XPiNC): http(s)://[yourserver]/[application.nsf]/[viewname|0]/[UNID| ViewKey]/$File/[Attachm [read] Keywords: domino ibm ldd lotus notes xpages application database development javascript server
233


A Quick Question for Administrators...
Tue, Jun 10th 2014 6:14a   Serdar Basegmez
Just a quick question. Especially large domains have lots of users with the same full name. In modern directory systems, we can decrease the possibility of conflict by using hierarchical naming, however that will become an issue eventually, when you need to specify an e-mail address. I have seen that adding a number to the first or last name (John Smith , John 1 Smith, etc.) is highly popular. How do you handle people with the same name in your environment (e.g. Domino, AD, Connections, et [read] Keywords: connections domino lotus
683


RIP Tim Tripcony...
Mon, May 12th 2014 1:55p   Serdar Basegmez
As many friends around, we are shocked and deeply saddened by unexpected loss of our own Tim Tripcony. Tim Tripcony was one of the most talented developers I have met... He inspired all of us by challenging all kinds of limits in our platform and finding really elegant patterns in various problems. He was always polite, helpful and positive with people. RIP, my friend. You'll be missed a lot. [read] Keywords:
359


E-mail will be dead... For some people...
Sat, Feb 22nd 2014 5:14a   Serdar Basegmez
Just an off-topic post, but can't help blogging about that. We are having bad times in our country. Summaries in English can be found here, here and here. Last two incidents are strongly related to very social context of our information and technology domain... Welcome to the remake of Orwell's 1984... The first is the change in the "Internet Bill", legal changes around monitoring and censorship. According to the bill, a government official, head of Turkey's telecommunication autho [read] Keywords: ibm blogging network
581


IBM Connect 2014 slidedeck on the IBM Social Business Toolkit SDK
Thu, Feb 6th 2014 10:14a   Serdar Basegmez
It's been a week after my session with Graham Acres. Sorry about the delay but we needed some time to prepare demo databases... Here is the slidedeck: And demo databases: https://github.com/sbasegmez/ic14demos [read] Keywords: ibm development
249


BP308 - The Journey to Becoming a Social Application Developer
Tue, Jan 21st 2014 5:09a   Serdar Basegmez
This is going to be my third IBM Connect and second session. Excited! Last year, my session co-presenter was my dear friend Bruce Elgort. I feel privileged this year again, because I am sharing the stage with a great speaker, Graham Acres... The session is all about the IBM Social Business Toolkit SDK, which has been first announced at Lotusphere 2011. After three years, we will see much more content about it this year. Since first hearing about the toolkit, I had trouble under [read] Keywords: connections domino ibm lotusphere notes xpages application applications integration java javascript openntf twitter




270


My previous blog post was ’Hot’!
Sat, Dec 7th 2013 2:47a   Serdar Basegmez
Yesterday, I have blogged about the renewal of my IBM Champion title. This morning I woke up with lots of notifications on my mobile. Apparently, my dear friend Bruce liked my blog post very much and he has posted it everywhere (Twitter, Facebook, Linkedin Google Plus). The real surprise was on PlanetLotus waiting for me :) Wow! I must be really famous and people want to know about my happiness. Thank you all! :) OK I'm joking. Many of you know it but for those who are not aware of [read] Keywords: ibm database facebook google linkedin mobile planetlotus twitter
289


Still part of it: IBM Champions
Fri, Dec 6th 2013 6:11a   Serdar Basegmez
Yesterday, Oliver Heinz and Joyce Davis announced IBM Champions of 2014. I have been recognized as IBM Champion for the third time but it's still exciting like the first time :) Congratulations to everyone, especially new champions. 2014 IBM Champions So proud to be listed here, with these fantastic people... But remember, there are many great people outside of this list. They might not have the title for this time but they are helping others and improving the value of the te [read] Keywords: connections foundations ibm community
175


Change is good...
Mon, Nov 18th 2013 5:22a   Serdar Basegmez
Yes! Change is good... For a couple of weeks, I've been working on Bootstrap and as I learn it, my blog became a great playground for me! It's still using Domino Blog template at the back-end but skin is completely renewed. I have not optimized for performance yet but I can tell you, our blog template is so powerful that I have not changed anything in the application design! Please share your thoughts and tell me if you see any problems! BTW, I can share my templates in case you [read] Keywords: domino application
230


Thank you Mr. Bruce Elgort...
Wed, Oct 2nd 2013 10:12a   Serdar Basegmez
Before writing this post I tried to remember when I have met Bruce for the first time. It was just 2.5 years ago when I received a twitter DM from him. I was at an airport in Germany waiting the boarding time. I remember had a short discussion over Skype. 2.5 years? Really? I feel like I know Bruce for decades. Bruce Elgort is one of the founders of OpenNTF, which is a very important initiative which bands passionate developers together, improves communication and collaboration within [read] Keywords: collaboration ibm lotus lotusphere notes blogger community openntf podcast skype taking notes twitter




Created and Maintained by Yancy Lent - About - Blog Submission - Suggestions - Change Log - Blog Widget - Advertising - Mobile Edition