Sie können mich buchen für:
Individuelle Schulungen für XPages, JavaScript und Appcelerator Titanium Software-Entwicklung für IBM XPages, Appcelerator Titanium (Mobile Apps iPhone, iPad, Android, Blackberry 10), Mobile Web und IBM Notes
Help needed: setEditMode() function does not work in 8.5.2 anymore - why?
Julian Buss, March 14th, 2011 18:00:01
Tags:  XPages 
Back in the days of 8.5.0 I needed a function to set a document data source in editmode or readmode programmatically via SSJS. I found the following solution in a forum:

---
function setEditMode(doc:NotesXSPDocument, editmode) {
var cl:java.lang.Class = java.lang.Class.forName("com.ibm.xsp.model.domino.wrapped.DominoDocument");
                var method:java.lang.Method;
                var paramTypes = new Array();
                paramTypes[0] = java.lang.Boolean.TYPE;
                method = cl.getMethod("setEditable", paramTypes);
                var params = new Array();
                params[0] = new java.lang.Boolean(editmode);
                method.invoke(doc, params);
}        
---

which worked perfectly in 8.5.0 and 8.5.1. For some reason it does not work in 8.5.2 anymore, I get an exception that the class com.ibm.xsp.model.domino.wrapped.DominoDocument was not found.

Does anyone have a solution? How do you set a document data source into editmode via SSJS?
Comments (6) | Permanent Link

Comments:
1) Help needed: setEditMode() function does not work in 8.5.2 anymore - why?
Karsten Lehmann 14.03.2011 19:58:39

Haven't tried it yet, but you could try the following:

var cl:java.lang.Class = com.ibm.domino.xsp.module.nsf.NotesContext.getCurrent().getModule().getModuleClassLoader().loadClass("com.ibm.xsp.model.domino.wrapped.DominoDocument");

2) Help needed: setEditMode() function does not work in 8.5.2 anymore - why?
Rajeev Menon 14.03.2011 20:07:17

Have you tried NotesXspDocument.setEditable(true/false)?

3) Help needed: setEditMode() function does not work in 8.5.2 anymore - why?
Philippe Riand 14.03.2011 22:50:17

2) Should not work, as the setEditable() is not published to JS, for the good reasons (code conflicts with the methods bellow)

To change the document mode, you have different solutions:

- Initially, you compute the mode in the data source attributes

- There is a simple action you can use (ChangeDocumentMode)

- There is an API in the context object: context.setDocumentMode(), which does what the simple action does.

Julian, you have an article in your XPages wiki explaining it :-) ({ Link } )

Now, Class.forName() cannot work in 8.5.2 because of OSGi. Class.forName() is executed by the plug-in hosting the JS interpreter, which doesn't have any dependency on the XPages plug-ins. As such, Class.forName() can't work. It used to work in 8.5 as all the jar files where loaded by the same class loader, as they were all in the same directory.

Although the solution provided by Karsten would work, it uses many undocumented classes, so use it as you're own risk... More generally, you can get the current class loader from Thread.currentThread().getContextClassloader(), as specified in the J2EE spec. But this might fail as you need to be 'trusted' by the security manager to access the currentThread. Instead, you can use facesContext.getContextClassloader(). This is a method we added in FacesContextEx.

4) Help needed: setEditMode() function does not work in 8.5.2 anymore - why?
Julian Buss 15.03.2011 08:41:41

Philippe, thanks, I didn't saw the obvious :-)

The context.setDocumentMode() helps me in my current case, nevertheless we need a documented method to set a specific data source into edit mode via SSJSS.

Usecase for example: a button "edit" which checks for various conditions (user has a role, editing allowed at the moment and so on) and enables edit mode on a certain data source if these conditions are met.

5) Help needed: setEditMode() function does not work in 8.5.2 anymore - why?
Julian Buss 15.03.2011 08:49:33

Karsten, your method works, thanks.

Philippe, this does not work:

var cl:java.lang.Class = facesContext.getContextClassloader().loadClass("com.ibm.xsp.model.domino.wrapped.DominoDocument");

6) Help needed: setEditMode() function does not work in 8.5.2 anymore - why?
Philippe Riand 20.03.2011 21:00:31

Sorry, getContextClassloader() should in fact spell .getContextClassLoader(), with a capital L for Loader

Add a comment
Subject:
   
Name:
Mail:
Web:
 
Comment:  (No HTML - URLs with leading http://)
 
remember me?   
You can hire me.
See my Linkedin profile for details.

Thanks for reading and have a nice time here!

Please note my Apps for iPhone and iPad: NotesBook: takes your Lotus Notes Notebook (Journal) to your iPhone and iPad xpageswiki.com: huge XPages Tips & Tricks collection for iPhone and iPad