How to stop JSF reload page "onclick"?
I get result to JavaScript from native NPAPI/XPCOM/ActiveX. Previously user activate native GUI by:
<h:commandLink styleClass="send-doc-link" value="#{msg.send}" onclick="javascript:signDocument('data');return true;" action="#{internalPayment.sendDocument}"/>
and JavaScript function 'signDocument' finish execution after user quit from add-on GUI.
I switch native code to asynhronouse model. So JS func 'signDocument' return execution imediatly and result must be fetched lately.
I write JS code, like this:
function signDocument(dataTagID, tagID4Event) { var npapi = document.getElementById("npapi"); npapi.Sign(langId, content, desc, ts, sign); mylog("OK"); var scheduler = setInterval( function() { mylog("FAIL"); 开发者_运维知识库 if (npapi.AddonGetState() != "finished") return; clearInterval(scheduler); out_sign = npapi.SignValue(); fireHTMLEvent(tagID4Event, 'click'); }, 1000); } }
which try get result in 1 sec interval and emulate link pressing by firing 'click' event. All work fine on test static HTML test.
I rewrite .jsf file to:
<h:commandLink styleClass="send-doc-link" value="#{msg.send}" onclick="javascript:signDocument('data', 'signDocumentCallbackID');return true;"/> <t:commandLink styleClass="hidden" id="signDocumentCallbackID" forceId="true" onclick="return true;" action="#{internalPayment.sendDocument}"/>
I expect that scheduler fetch result and fire event. But scheduler do not invoked because after user click to first link (visible) JS call native code which create separate thread for GUI and execution returned to JS. Next page reloaded and seems all JS object die as page die (I check this by 'mylog' func).
Really first h:commandLink
tag converted to:
<a href="#" onclick="var cf = function(){javascript:signDocument('data', 'signDocumentCallbackID');return true;};var oamSF = function(){return oamSubmitForm('j_id_jsp_179411707_1','j_id_jsp_179411707_1:j_id_jsp_179411707_5');};return (cf()==false)? false : oamSF();" class="send-doc-link">...
So to my JS code added oamSubmitForm
which seems reload my page and delete sheduler.
How stop include special code to onclick=""
?
If you don't need to invoke a synchronous backing bean action with a link, then just replace <h:commandLink>
by <h:outputLink>
or just <a>
.
<h:outputLink styleClass="send-doc-link" onclick="signDocument('data', 'signDocumentCallbackID')">
<h:outputText value="#{msg.send}" />
</h:outputLink>
or
<a href="#" styleClass="send-doc-link" onclick="signDocument('data', 'signDocumentCallbackID')">
<h:outputText value="#{msg.send}" />
</a>
Note that the javascript:
pseudoprotocol and the return true;
are totally superfluous. Both are already the default. You would probably also use return false;
instead so that the link's default action (going to top of page) will be blocked.
精彩评论