2012-07-07 74 views
0

我的JSF页面如下禁用按钮回发在JSF2.0

<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更新。由于postback/jsf life cylce电话,我的变化正在迷失。

使用萤火虫检查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 /面/的index.xhtml' 使用萤火我得到预期的输出。

是否有任何标签或机制来删除回传呼叫?

回答

0

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

您可以改用 <h:commandButton>和提类型= “按钮” 是这样的:

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

Documentation

+0

由于拉维它果然奏效............. – 2012-07-08 05:28:46