bookmark_borderQUINDIP: document your code properly in LotusScript

Hi

this is not related to xPages but to LotusScript:

we have started years ago to use “kind-of” javadoc-ish style of documentation of our code:

and just today i figured it actually is used using typeahead (similar as in the java editor):

really neat 😉

enjoy

bookmark_borderQUINDIP: intercept wrong/inexistent documentId

Hi

long time no post… but alas.. finally something I really like:

Have you ever had the situation, that you have a xPage which is workflow enabled, and you have (maybe) multiple servers? Some users might even use the LN client front-end on another server. The workflow sends out a mail telling the approver to approve.

Boom… the document did not yet replicate to the target server…

you do not want either of this message displayed:

what to do?

hmm.. I first tried with this, sorry, was not happy with it…

thing is: we use the same xpView for production and for archive, only the data source changes in the background. This will open the documents from the archive with such an URL:
http://server/db.nsf/%24%24OpenDominoDocument.xsp?databaseName=server!!otherDb.nsf&documentId=6496BA354B37544CC1257C680059C04B&action=openDocument

I could not get this to work..

So I had to figure out another way to intercept a “wrong” documentId.

Solution: use a phaselistener!!! (how to implement see here, kudos to Sven)

Now I only need to intercept the first phase in the JSF lifecycle, test if the supplied documentId exists and redirect:

event.getFacesContext().getExternalContext().redirect(“xpDocumentNotFound.xsp”);
event.getFacesContext().responseComplete();

I do some checks and then call redirect and responseComplete which executes immediately and does not continue with the other JSF phases

and the best thing: this is UNIVERSAL!!! I don’t need to implement it for all xPages I use!

bookmark_borderQUINDIP: set JAVA Compiler target in notes.ini

Literally EVERY time I created a Java agent or library the compiler target was set to 1.2 even though I have been using LN 7 or later…
I always had to find the noteId and use a tool to manually change the source and target to 1.6.

here’s how you can change that behaviour:
http://www-10.lotus.com/ldd/ddwiki.nsf/dx/07152009034956PMMSTR75.htm

enjoy

AND make sure you add an EMPTY at the end in case JavaCompilerTarget=1.6 is your last line! otherwise this setting will not be used!

bookmark_borderQUINDIP: need to run an agent as signer from an xPage?

we needed a possibility for users to “override” the workflow, ie. interfere even though they were not “authors” at the moment. The only way was to do with an agent running with more access rights.

solution was: us “sessionAsSigner”

this would not work:
var agent = currentDatabase.getAgent(“(agnXPageWFMoveToState60)”);
agent.runWithDocumentContext(currentDocument.getDocument() );
return “xsp-reopen”;

this did work (kudos to Sven Hasselbach):
var agent = sessionAsSigner.getCurrentDatabase().getAgent(“(agnXPageWFMoveToState60)”);
agent.runWithDocumentContext(currentDocument.getDocument() );
return “xsp-reopen”;

hope this helps some people to achieve similar things

bookmark_borderINDIP: add visual indicator to type ahead

that’s how it looks:

field with type ahead waiting for input:
field with type ahead thinking
field with type ahead failure

this is the XML code of the field for the events:
<xp:eventHandler event=”onkeypress” submit=”false” id=”eventHandler2″>
<xp:this.script><![CDATA[if (event.keyCode==9 || event.keyCode==13){
removeVisual(‘view:_id1:inputText3’)
}else{
addVisual(‘view:_id1:inputText3’);
}]]></xp:this.script>
</xp:eventHandler>

<xp:eventHandler event=”onblur” submit=”false” id=”eventHandler3″>
<xp:this.script><![CDATA[removeVisual(‘view:_id1:inputText3’)]]></xp:this.script>
</xp:eventHandler>

and this is the style assigned to the field:
<xp:this.styleClass>
<![CDATA[#{javascript:if( currentDocument.isEditable()){ return ‘useTypeAhead’; }}]]>
</xp:this.styleClass>

this is needed in the CSS:
.useTypeAhead{
background: #fff url(“TypeAhead.gif”) no-repeat right;
}
.dijitValidationContainer{
width: 20px;
}
.dijitValidationContainer .dijitValidationIcon{
width: 20px;

this is needed in a CSJS library (cudos to Mark Roden and Sven Hasselbach)
function x$(idTag, param, jd){ //Updated 28 Feb 2012
// hardcoded
idTag=idTag.replace(/:/gi, “\:”)+(param ? param : “”);
return( jd==”d” ? “#”+idTag : $(“#”+idTag));
}

var inputField;

//addVisual function used to add a loading image to the screen and make it visible
//expected input string similar to view1_:id1_:viewPanel1
function addVisual(idTag){
var newImage=”url(‘loading.gif’)” //Change me for your server
inputField=dojo.query(x$(“widget_”+idTag, ” .dijitValidationIcon”, “d”))
inputField.style(“backgroundImage”, newImage);
inputField.style(“visibility”, “visible”);
inputField.style(“backgroundRepeat”, “no-repeat”);
inputField.style(“backgroundPosition”, “right”);
dojo.query(x$(“widget_”+idTag, ” .dijitValidationContainer”, “d”)).style(“display”, “block”)
inputField.attr(“value”,””)

}


//— hijack dojo XHR calls
//Thanks to Sven Hasselbach for this ajax intercept code
//
var typeAheadLoad;

dojo.addOnLoad( function(){

 /*** hijacking xhr request ***/
 if( !dojo._xhr )
    dojo._xhr = dojo.xhr;

 dojo.xhr = function(){
    try{
       var args = arguments[1];
       if( args[‘content’] ){
          var content = args[‘content’];
             if( content[‘$$ajaxmode’] ){
                if( content[‘$$ajaxmode’] == “typeahead” ){
               
                   /*** hook in load function ***/
                   typeAheadLoad = args[“load”];

                   /*** overwrite error function ***/
                //   args[“error”] = function(){
                 //     alert(‘Error raised!’)
                //   };
                   
                   /*** hijack load function ***/
                   args[“load”] = function(arguments){
                      /*** On Start ***/
                     // alert(“On Start!”);
                   
                      /*** call original function ***/
                      typeAheadLoad(arguments);
                   
                      /*** On Complete ***/
                  if (arguments.toLowerCase()==”<ul></ul>”){
                  var newImage=”url(‘typeAheadFailure.gif’)” //Change me for your server   
                  inputField.style(“backgroundImage”, newImage)   
                  }else{
                  inputField.style(“background”, “white”)
                  }
                   };
               }
           }
       }
    }catch(e){}
    dojo._xhr( arguments[0], arguments[1], arguments[2] );
 }
});


//removeVisual function used to remove the loading image from the screen and make it hidden
//expected input string similar to view1_:id1_:viewPanel1
function removeVisual(idTag){
var inputField=dojo.query(x$(“widget_”+idTag, ” .dijitValidationIcon”, “d”))
inputField.style(“backgroundImage”, “”)
inputField.style(“visibility”, “hidden”)
dojo.query(x$(“widget_”+idTag, ” .dijitValidationContainer”, “d”)).style(“display”, “none”)
}

//Checks to see if the visual icon is still running – if so then assume fail and kill it
function checkTimer(idTag){

dojo.query(x$(“widget_”+idTag, ” .dijitValidationContainer”, “d”)).style(“display”, “none”)

}

bookmark_borderINDIP: how to figure out the id of an element which triggered an event!

here’s the scenario:

We have what we call dynamic tables. It lets the user add as many rows as he requires. Really neat.
In some of the fields we use type ahead.

Recently I figured: it would be nice to see an indicator if the server is “thinking”… something like
I could do it easily via one specific field from which I knew it’s id …

But in those dynamic tables I have no clue on which field the event for type ahead was triggered….

until now:
Cudos to Paul Calhoun with his incredibly useful tips about CSJS (something I usually avoid as much as I can)

There I found the solution! You can call SERVER side JS from CLIENT side JS… isn’t that fantastic?

here’s how:
call the SSJS like this:
“#{javascript:<ServerSide JavaScript>}”

example to alert the id of an element via it’s event, in this case onFocus, which was triggered:
alert( “#{javascript:BackingBean.getElementId(this)}” )


For those ones interested what the getElementId does in my Java Bean:
UIInput input = (UIInput) handler.getParent();
return input.getClientId(FacesContext.getCurrentInstance());

Of course the UIInput could be changed to something more generic like UIComponent

stay tuned for my next blog which tells how I achieved proper visual indication

bookmark_borderINDIP: beware of the document.copytoDatabase method!

We had to merge two applications, so I created a background agent which copied all required documents to the “new” database. The customer tested and we set a due date for the real migration.
The night before actual migration I run an agent which deleted all “test” migration documents before the real agent to copy the documents run again!

Next morning I came to the office and thought: oh my dear. something went wrong! Only a few dozen documents had been copied, I thought!

So I rerun the agent again. First all seemed to be fine. Then a few hours later documents started disappearing. With no obvious reasons.

It took me about 3 hours to figure out that the method document.copyToDatabase would create the same UniversalId again!

So after having deleted the first round of “test” documents and recopied again at due date, the universalids of the documents had been in the deletion list of the LN db already. That’s why they started disappearing again after a while!

So I had to delete everything again to make sure, rerun the copy agent again but this time change the universalid.

Took me roughly a day to fix everything, something which normally would have taken about one hour.

bookmark_borderINDIP: How do you export data from an web application into Excel?

You could use POI to write an Excel file, but writing to a file with APIs is usually really slow.

MYYYYYYYYYYYYYYYYYY approach is blazingly faaaaaaaaaaaaaaaaaaaaast……..

In our company we are in the lucky situation that we have single-sign-on on the web towards our Domino servers. This is important for the following solution to export documents to work properly.

Steps:
1. Create some kind of “profile” document which defines the filters for the data the user wants to export
2. Create an agent which processes those filters from the profile document and outputs XML for all documents
Example XML:
<?xml version=”1.0″ encoding=”UTF-8″?>
<data xmlns:xs=”http://www.w3.org/2001/XMLSchema-instance”>

<document>
<processeddate xs:nil=”true”></processeddate>
<wfcurrentstate><![CDATA[70]]></wfcurrentstate>
<wfcurrentstatename><![CDATA[Returned for modification]]></wfcurrentstatename>
<timecreated>2013-10-08</timecreated>
<regionname><![CDATA[SOUTH AMERICA]]></regionname>
</document>
</data>

Important here is only the “xs:nil” attribute for “empty” fields, dates/numbers you can submit as is, text fields I advise to put into the <![CDATA[textvalue]]> format.
3. Import the XML via the URL of the web agent (eg. http://yourserver/yourpath/youragent?openagent) file into Excel via Data Import from other sources from XML data import.
Now the first time you do this you are have to go through some wizard actions done by Excel.
Once the XML map  has been created you can use that file over and over again (say as template). You simply need to refresh the data via the data tab in Excel.
My development workflow (to get this working start slow)
first only export some text fields
then try also empty fields (with the xs:nil) attribute
then continue with numbers and dates to see if it works
call the agent directly in the browser to check if the XML is properly formatted (Google Chrome will tell you so, maybe other browers as well)
then import that XML into Excel, ie. use the refresh button
I use to “log” the filters from the profile when the agent runs. My agent uses mostly FT Search to find the documents, only if more than 5000 are found it reverts to (if possible) view categories.
The “constructed” query is also logged. That way I can run the same query directly in the LN client to check for FT Query mistakes. As example I figured I need to put texts into double quotation marks to make queries, with filters consisting of more than one word, properly working.
The result is phantastic! I can export 5000 documents via VPN connection from my home office in about less than 30sec!
Questions? please don’t hesitate to write comments
otherwise enjoy!!!