Pages

Wednesday, March 16, 2011

Crash a Domino Server - oops SSJS did it

In an attempt to simulate @DbColumn using SSJS, i used a few lines of code which included the following,

doc.getColumnValues();


To my astonishment, I found that my domino server had crashed. Yes the server it self had crashed every time it read this code fragment.

I have coded a few lines in the past that crashed Lotus notes client/designer, but never had the opportunity to crash a server. And now it took me XPages to do it :)

Looking for a work around :(

Monday, March 14, 2011

Execute Client Scripts in the After Page Load event of XPage

 In order to execute client side scripts in the after page load events of an XPage, one must use dojo to accomplish it. I think I know an other way to do this, but the one posted below seems simple and effective to me. All you got to do is add the following to your XPage and test it for your self

     dojo.addOnLoad(yourJavascriptFunction)


Hope this helps :)

Wednesday, March 9, 2011

Triggering Client script from server side : Xpages

Triggering client script from server side on XPages saves developers in many scenarios.
I missed them so badly until I came to know about the "xp:onComplete" tag.

Associate this property to the event handler of any of the controls with partial refresh enabled and voila you are ready to go.

The following is a simple example on getting the property to work in xpages.


Ensure that the control does not have full update enabled cos, this method would work only when partial refresh is enabled

Handling "java.lang.OutOfMemoryError" - notes.ini Keyword: JavaMaxHeapSize

Syntax: JavaMaxHeapSize=number of bytes

Example: JavaMaxHeapSize=67108864

Default value: 67108864 (64mb)

Description:
Specifies the maximum--not initial--size the Java heap can reach. The Java Virtual Machine (JVM) starts out at 16MB of heap space and most of it is uncommitted. If the JVM needs more heap than it currently has, it will expand the heap in increments but will not exceed the maximum. Exceptions such as "java.lang.OutOfMemoryError" indicate that a heap has reached its maximum size. You can specify the number of bytes directly or use the suffix "MB" to indicate megabytes, for example, specifying "64MB" is the same as specifying "67108864."

Resource obtained from : http://www.lntoolbox.com/en/notesini-reference/bycategory/serverconfiguration/14-Server_Configuration/1148-javamaxheapsize.html
Hope this helps :)

Empty Contents of an IFrame - Javascript

Following is one effective way that can help one to empty the contents of an iFrame.

window.frames['iFrameID'].location.href="about:blank";

Following are a few other methods that might work,

window.frames[['iFrameID'].location.href=" ";

window.frames[['iFrameID'].location.reload();
window.frames[['iFrameID'].document.close();
window.frames[['iFrameID'].document.body.innerHtml="";

hope this helps :)

Tuesday, March 1, 2011

Accessing parent from an iFrame

Accessing a the parent page which contains an iframe from with in the iFrame is as follows,

var parentDOMDoc=parent.document

again, access restrictions are applicable here i.e if the IFrame's document are not in the same domain as the parent frame, then you may be denied access to it's contents due to security features of most browsers.

Accessing iframe contents using javascript

The following is a way to access the contents of an IFrame.

var ifrm = document.frames["myIFrame"].document.forms[0]

This should return the form element associated with the iframe. In most cases where the above code fails try using window.frames instead of document.frames and that would work.

On top of this if the IFrame's document is not in the same domain as the parent frame, then you may be denied access to it's contents due to security features of most browsers.

Monday, February 28, 2011

how to repeat triggering a javascript function automatically

The setInterval function in javascript helps the browser to execute a javascript function repeatedly over a time period and its syntax is as follows

setInterval( myFunction, noOfSeconds*1000) , where

setInterval is the name of the native javascript function
myFunction is the name of your custom function that needs to be triggered repeatedly
noOfSeconds is the time gap in number of seconds after which your custom function needs to be executed again

Once the setInterval is invoked, the stop the same the clearInterval command should be invoked.The syntax of the same is as follows,

clearInterval(myFunction)

Wednesday, February 23, 2011

Issue : dojo.xhrGet fails in Safari

It was one trouble some situation when I found that my dojo.xhrGet failed in Safari. I felt like I was hanging in a cliff 500 feet deep. with no way back :( untill I stumbled upon the following forum discussion,

http://www.devcomments.com/cross-site-ajax-using-dojo-xhrGet-doesn-t-work-as-expected-but-at200443.htm

An amazing one. The first few posts are not visible for some reason but the vital ones that resolved the issue where visible.

The abstract of what I understood from issue that I faced and the discussion in this forum are as follows,

1. When using dojo.xhrGet, a preflight request get triggered from safari. And that means an Ajax request is triggered to the server before server authentication could occur. And this posed a severe security threat as Anonymous access to my Lotus Notes Database has to be enabled for dojo.xhrGet to work on Safari.

2. The trick was to use dojo.xhr instead of dojo.xhrGet . The documentation on  dojo.xhr can be found in the following location -http://dojotoolkit.org/api/dojo.xhr

3. The context that we need to understand here is that dojo.xhrGet({arguments}) is same as dojo.xhr("GET",{arguments}). And this is one of the vital points that resolved the issue

In addition to the above, to tackle the preflight request issue, it is better, if one can check on the play around with the "sync" flag. It is not that playing around with this will definitely resolve the issue but there are paucity of chances that it might help.

Hope this helps :)