Pages

Friday, February 12, 2010

#6 : Bugs I Found : Javascript comments get compiled in XPages

I had the following code in a button on the XPage.
try {
var id="#{javascript: getComponent(prototype.name).getId()}"; //---this line produces error
    alert(id);
} catch (error)    {
    alert(error.message);
}
When I attempted to open the XPage , I got the following error,
 /**********************************************************/
Unexpected runtime error
The runtime has encountered an unexpected error.
500 Exception
Error while executing JavaScript action expression
Script interpreter error, line=1, col=30: 'getComponent()' is null

►  Stack Trace

 /**********************************************************/

Hence I attempted something different after commenting the same line as follows
try {
//var id="#{javascript: getComponent(prototype.name).getId()}";
var id="#{javascript: getComponentInstanceId()}";
    alert(id);
} catch (error)    {
    alert(error.message);
}

and previewed the same on the notes client...
Oops.... got the same error ....

After tinkering a bit, I removed the comment and placed a code as is mentioned below,
try {
var id="#{javascript: getComponentInstanceId()}";
    alert(id);
} catch (error)    {
    alert(error.message);
}


and that worked.....

A possible bug with javascript comments in XPages

No comments:

Post a Comment