Solved

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

Posted on 2011-09-23
4
1,759 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now