Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-09-23
4
Medium Priority
?
1,910 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
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.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

886 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