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

I get result to JavaScript from native NPAPIXPCOMActiveX. Previously user activate native GUI by:<

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745623601a4636669.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信