最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to stop JSF reload page "onclick"? - Stack Overflow

programmeradmin2浏览0评论

I get result to JavaScript from native NPAPI/XPCOM/ActiveX. Previously user activate native GUI by:

   <h:mandLink 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:mandLink styleClass="send-doc-link" value="#{msg.send}"
    onclick="javascript:signDocument('data', 'signDocumentCallbackID');return true;"/>
  <t:mandLink 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:mandLink 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=""?

I get result to JavaScript from native NPAPI/XPCOM/ActiveX. Previously user activate native GUI by:

   <h:mandLink 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:mandLink styleClass="send-doc-link" value="#{msg.send}"
    onclick="javascript:signDocument('data', 'signDocumentCallbackID');return true;"/>
  <t:mandLink 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:mandLink 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=""?

Share Improve this question edited Jun 21, 2011 at 11:06 gavenkoa asked Jun 21, 2011 at 11:00 gavenkoagavenkoa 49.1k28 gold badges270 silver badges337 bronze badges 1
  • h:mandLink will add form submit logic when render on onClick, you should consider simple anchor tag if you want no extra javascript. – Asad Rasheed Commented Jun 21, 2011 at 11:09
Add a ment  | 

1 Answer 1

Reset to default 3

If you don't need to invoke a synchronous backing bean action with a link, then just replace <h:mandLink> 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.

发布评论

评论列表(0)

  1. 暂无评论