Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

23 Experts available now in Live!

Get 1:1 Help Now