-
I code in a local template, then refresh to a remote server, then hit that server using a browser like an actual user would. Every now and then, quite sporadically, updates done to an XPage simply do not “take”.
-
This just happened while fiddling with a sample application for a PMR. In this instance I have a script block at the bottom of the XPage, and I stripped most of the code out of this script block, leaving it there but with only a few lines of JS that really do nothing other than have something to run.
-
When I “Build Project” and applied changes, the old script block code keeps running. I know this because the deleted code contained a reference to an Agent that doesn’t exist in the sample, and the server console keeps complaining that the Agent can’t be found.
-
When I search for code that would touch off that Agent, I find it … in the .java file. When I look, I see a private UIComponent createScriptBlock() method in that .java file, and it clearly contains code that no longer exists on the XPage.
Here’s the script block:
<xp:scriptBlock>
<xp:this.value escape="false"><![CDATA[
window.onunload=function() {
if(!userClick) {
userClick=false; // Only skip once
} // !userClick
} // onunload
var userClick=false;
var debug=true;
]]></xp:this.value>
</xp:scriptBlock>
Here’s the corresponding .java after building it:
private UIComponent createScriptBlock(FacesContext context,
UIComponent parent, PageExpressionEvaluator evaluator) {
XspOutputScript result = new XspOutputScript();
String sourceId = "/xp:view[1]/xp:scriptBlock[1]/xp:this.value[1]/text()";
String valueExpr = "window.onunload=function() {\n\tif(!userClick) {\t\t\t\t\t\t\t\t\t\t// User button click prevents this\n\t\tdoAjax({\n\t\t\t\"OP\" : \"Unlock\",\n\t\t\t\"User\" : \"#{javascript:@UserName();}\",\n\t\t\t\"UNID\" : \"#{javascript:doc.getDocument().getUniversalID();}\"\n\t\t}, \"(doIt)\", -1, \"File unload\", \"#{id:catsMsg}\");\n\t\tuserClick=true;\t\t\t\t\t\t\t\t\t// User click consumed\n\t} else {\n\t\tif(debug) console.log(\"* File: User click unlock bypass *\");\n\t\tuserClick=false;\t\t\t\t\t\t\t\t\t// Only skip once\n\t} // !userClick\n} // onunload\nvar userClick=false;\nvar debug=true;";
ValueBinding value = evaluator.createValueBinding(result, valueExpr, sourceId,Object.class);
result.setValueBinding("value", value);
return result;
}
-
When I build this after entering all the above, the .java is correct.
-
At this point I would normally abandon this post on the assumption that I simply forgot to build it, but I know this script block is all I edited, and when I look at the status bar history, I see the Xpage was the only thing updated. This means either DDE updated only this one Xpage without any changes to it, in which case I did forget to rebuild it, or I did in fact rebuild it and DDE’s automagic failed. At this point it’s impossible to prove one or the other, unless it’s in a log somewhere.
Thanks for your time…