简体   繁体   English

在jsf中使用f:ajax时如何删除ajax

[英]How to remove ajax when use f:ajax in jsf

I use ajax in my web page, then I remove it. 我在网页中使用ajax,然后将其删除。

My code: 我的代码:

<h:commandButton type="submit" value="Test">
    <f:ajax listener="#{connectionController.testConnect()}" execute="@form" render="msgCon"/>
</h:commandButton>
<h:commandButton id="btnCreate" type="submit" value="Create" action="#{connectionController.insertConnection(accountController.accLogin.id)}"/>
<h:commandLink styleClass="cmdLink" value="Cancel" onclick="clearConn()"/>

But when I run page again, generated code: 但是当我再次运行页面时,生成了代码:

<input id="form:j_idt49" type="submit" name="form:j_idt49" value="Test" onclick="mojarra.ab(this,event,'action','@form','form:msgCon');return false">
<input id="form:btnCreate" type="submit" name="form:btnCreate" value="Create">
<a href="#" onclick="jsf.util.chain(this,event,'clearConn()','mojarra.jsfcljs(document.getElementById(\'form\'),{\'form:j_idt50\':\'form:j_idt50\'},\'\')');return false" class="cmdLink">Cancel</a>

Why does the cancel button still have ajax? 为什么取消按钮仍然具有Ajax? How to fix it? 如何解决?

That's not ajax. 那不是ajax。 You're confusing "JavaScript" with "Ajax". 您将“ JavaScript”与“ Ajax”混淆了。 You're probably also confusing the HTML representation of <h:commandButton> with <h:commandLink> . 您可能还会将<h:commandButton>的HTML表示与<h:commandLink>混淆。 Those jsf.util.chain() and mojarra.jsfcljs() have got nothing to do with ajax. 那些jsf.util.chain()mojarra.jsfcljs()与ajax无关。 They just make it possible to submit a POST form using a plain link instead of a submit button. 他们只是使使用纯链接而不是提交按钮提交POST表单成为可能。 In plain HTML it's not possible to submit a POST form using a plain link. 在纯HTML中,无法使用纯链接提交POST表单。 That's why those helper scripts are all there. 这就是为什么所有这些辅助脚本都在那里的原因。

To experiment further, add <f:ajax> inside the <h:commandLink> . 为了进一步试验,请在<h:commandLink>添加<f:ajax> <h:commandLink> You'll see that it get a mojarra.ab() function call in the generated HTML. 您会看到它在生成的HTML中获得了mojarra.ab()函数调用。 This will in turn indeed use ajax. 这实际上将使用ajax。 Or, replace <h:commandLink> by <h:commandButton> . 或者,将<h:commandLink>替换为<h:commandButton> You'll see that there are no helper scripts anymore to submit a form using a plain link. 您将看到不再有使用通用链接提交表单的帮助程序脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM