Solved

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

Posted on 2011-09-23
4
1,820 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 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