0

我的JSF页面如下

   <h:head>
        <title>Ajax Test</title>
    <h:outputScript name="giveEffect.js" library="jquery"/>
    <h:outputScript name="jquery.js" library="jquery"/>
</h:head>
<h:body>
    <div id="div1">
        <h:button id="b1" onclick=" button1Click(this)" value="#{kp.firstname}"/>
    <h:button id="b2" onclick="button1Click(this)" value="#{kp.home}"/>
    </div>
</h:body>
</html>

button1Click 是一个 jquery 函数,它执行 ajax 调用并更新我的页面。但是看不到ajax更新。由于回发/jsf 生命周期调用,我的更改正在丢失。

使用 firebug 检查 Dom。我找到了以下代码。

<div id="div1">
<input id="b1" type="button" value="Kar" onclick="button1Click(this); window.location.href='/AJAXTest/faces/index.xhtml'; return false;">
<input id="b2" type="button" value="Alike" onclick="button1Click(this); window.location.href='/AJAXTest/faces/index.xhtml'; return false;">
 </div>

假设我使用萤火虫消除了 window.location.href='/AJAXTest/faces/index.xhtml' 我得到了预期的输出。

是否有任何标签或机制来删除回发调用?

4

1 回答 1

0

按钮组件的结果属性用于确定由 onclick 激活的目标 URL。整个目标 URL 字符串将作为“window.location.href = ''”写入按钮的 onclick 属性。如果您有自定义 onclick 方法,则 window.location.href 将附加在脚本的末尾。由于您没有提及结果,它将导致对您当前视图的 GET 请求。

您可以改为使用 <h:commandButton>并提及 type="button" ,如下所示:

<h:commandButton id="b1" onclick=" button1Click(this)" value="#{kp.firstname} "type="button">

文档

于 2012-07-07T20:55:44.910 回答