I have an xPage on which I have added an button. On this button there is some serverside script executed when clicked.
What I would like is whenever a user clicks on a link in the menu this code is executed. Therefore I created the following code on the link element.
<xp:link loaded="true" escape="true" id="lnkTab"
value="#{javascript:rootNode.getFrame();}">
<xp:this.text><![CDATA[#{javascript://return rootNode.getLabel();
return rootNode.getLabel();}]]></xp:this.text>
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:sessionScope.selectedPage = rootNode;}]]></xp:this.action>
<xp:this.script><![CDATA[
var currentPage = "#{javascript: return this.getParent().getValue();}";
var currentPageLocation = window.location.href;
var lastSlash = currentPageLocation.lastIndexOf("/");
var page = currentPageLocation.substring(lastSlash+1,currentPageLocation.length);
if(page == "UserProfile.xsp" && currentPage != "UserProfile.xsp"){
if(isProfileChanged()){
debugger;
var retValue = confirm("U heeft wijzigingen niet opgeslagen.\nWilt u deze alsnog opslaan?");
if(retValue){
sendRedirectSignal("#{javascript: rootNode.getFrame();}","#{id:txtRedirectSignal}","#{id:btnProfileSave}");
thisEvent.preventDefault();
thisEvent.stopPropagation();
sendRedirectSignal("#{javascript: rootNode.getFrame();}","#{id:txtRedirectSignal}","#{id:btnProfileSave}");
return false;
}
}}]]></xp:this.script>
</xp:eventHandler>
</xp:link>
the code for the sendRedirectSignal is as follows
function sendRedirectSignal(strPage,redirectId,btnId){
var hidRedirect = dojo.byId(redirectId)
var btnProfile = dojo.byId(btnId);
if(hidRedirect!=null && btnProfile != null){
console.log(btnProfile);
hidRedirect.value = strPage;
console.log(btnProfile.click());
}
}
As you can see the code retrieves a button with dojo and issues the click event. For some reason this won't work at all. No event handlers are being executed on the button. When I execute the btn in firebug the code is being executed perfect. Can someone help on this issue? Why is the code not executed and how could I get it to work.