Solved

XPages: how can I add Server-Side JavaScript to a custom control property?

Posted on 2011-09-23
4
1,800 Views
Last Modified: 2013-12-18
I created a custom control with some buttons in it. I want these buttons to be generic, so the real code of the buttons should be passed in one of the properties. How should I create such a property? It works, for the Client-side JS it is no problem (type=String, editor=Client Side Script Editor), the server side code is different though, there is no such thing as a Server Side Script Editor.

The Type is ok, I only want the correct Editor. Or if you have a better way to create new event handlers in a custom control...?

0
Comment
Question by:Sjef Bosman
  • 2
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
Bill-Hanson earned 500 total points
ID: 36586440
Sure, no problem.  In this example, I will demonstrate how to add a custom querySave event handler to a simple Save & Close action button contained in a custom control.

1) In the custom control, add a property that will hold the function to be executed in our action button.  I'll call mine 'querySave'.  The property type must be 'javax.faces.el.MethodBinding'.  The editor must be 'Method Binding Editor'.

2). Here is the code behind the action button in the custom control for this example...
if (compositeData.querySave) if (!compositeData.querySave.call()) return;
currentDocument.save();

Open in new window

This says: If there is a function defined in the property 'querySave', call it.  If the function returns false, don't save the document.

3) Define a SSJS function that does what you need the action button to do.  I normally place mine in a SSJS library.  Make sure that the xPAge has access to the function.

4) In the xPage that contains this control, use the editor for the property we created in step 1 (querySave in this example) and enter the name of the function that you created in step 3.  IMPORTANT: Do not add the parenthesis or parameters when you enter the function name - if you do, the function will be executed at load time rather than when you click the action button.  Also, don't add any code directly to the editor, just the function name. Any code in this editor will also execute at load time.
0
 
LVL 46

Author Comment

by:Sjef Bosman
ID: 36586494
Clues for me: MethodBinding and Method Binding Editor. I thought I'd tried them all, there are too many and the explanation is, er, concise...

1, 2, 3 are clear
4 I do a little differently, here's my code that circumvents the problem you mentioned:

return function () {
      var viewPanel= getComponent("viewMails");
      var ids= viewPanel.getSelectedIds();
      dosomething(param.assoc, ids);
}

By the way, this XPages application is already running, but I now discover more and more nice features that I knew nothing about a year ago. A 2nd application is being developed that uses far less code that that 1st one. That's what Progress is, I suppose.

Thanks a bunch!!
0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 36586853
Anytime!  I feel the same way - I've learned tons since I started this project last year (about 16 months of development).  My Proposal Factory app now spans 8 databases and has been in Beta for a week now.  No bugs reported (yet), and the users love it!

Hey, thanks for the tip about defining the function right in the editor - I hadn't thought of doing that!
0
 
LVL 46

Author Comment

by:Sjef Bosman
ID: 36586932
Welcome!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question