Xpages - change document mode

Hi,

Is there any way to change the document mode with script (so to do the same in script as with “Change Document Mode” simple action)?

Thanks!

Tibor

Subject: This is not currently available but I’ve logged an enhancement request PHAN7QVSMP to be addressed in 8.5.1

Subject: solution

Thanks, anyway I’ve found a solution for this issue by using reflection. You can get a handle on the backend class for a domino document datasource (com.ibm.xsp.model.domino.wrapped.DominoDocument) and invoke the setEditable method manually (which is not available for NotesXspDocument).

Regards,

Tibor

Subject: can you give a code example, does not seem to work…

with doc as my data source I can do doc.getDocument(), but don’t have a setEditable(boolean) method there.

Can you give an example?

Subject: code example please

with doc as my data source I can do doc.getDocument(), but don’t have a setEditable(boolean) method there.

Can you give an example?

Subject: code example 2

Hi again, there’s another way to do it, use the method that John described to call Java functions from server side Javascript.

For the java part create a public function like this:

package util;

import com.ibm.xsp.model.domino.wrapped.DominoDocument;

public static void toggleMode(DominoDocument doc, boolean mode) {

doc.setEditable(mode);

}

(it doesn’t have to be static)

And then call if from any place where you can include server side js (button, script library etc.)

Tibor

Subject: code example

Hi, that’s a sample code for changing the document mode, I used it in the beforePageLoad event (to prevent opening a document in edit mode via url commands if it’s locked):

var dominoDoc:com.ibm.xsp.model.domino.wrapped.DominoDocument = dominoDocument1;

//dominoDoc.setEditable(false); cannot be done, DominoDocument will be replaced at runtime to NotesXspDocument

// do it with reflection, this way we don’t have to do a redirect

try {

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);

print("method: " + method);

var params = new Array();

params[0] = new java.lang.Boolean(false);

method.invoke(dominoDoc, params);

} catch (e) {

print(e);

// if it fails you can even set a session variable and based on that change the mode		

}

Tibor