对JSF j有一个问题:commandButton的动作,chrome浏览器和JSF 1.1
点击命令链接调用JavaScript函数,如下所示
<h:dataTable>
<h:column>
<h:panelGroup rendered="#{expression which returns true}">
<f:verbatim rendered="#{someView.agentEdit}"> </f:verbatim>
<h:commandLink id= "editId" styleClass="commandLinkClass"rendered="#policyHistory.agentEdit}" onclick="return performPolicyHistoryAction('Edit', id);" value="Edit"/>
</h:panelGroup>
</h:column>
</h:dataTable>
使用上面的代码我得到了链接,它能够调用js函数'performPolicyHistoryAction'
在js函数中
function performPolicyHistoryAction(cntrlValue, cntrlId){
DWREngine.setAsync(false);
if (cntrlValue == 'Edit') {
document.getElementById("someString:lnkViewOnlyrefresh").click();
}
}
和someString:lnkViewOnlyrefresh被声明为
<h:commandButton action="#{someBean.viewOnlyAction}"
id="lnkViewOnlyrefresh" value="refresh" styleClass="hide" title="refresh"></h:commandButton>
这里是chrome,而不是调用commandButton的action方法。它在IE和FF中运行良好
注意:如果我在&lt; h:commandButton&gt;的onClick中发出警告,我就会收到警报。
答案 0 :(得分:0)
更改为 onclick =&#34;返回performPolicyHistoryAction(&#39; ViewOnly&#39;,id); &#34; 更改为 onclick =&#34; performPolicyHistoryAction(&#39; ViewOnly&#39;,id);返回false;&#34;
in belowcode
<h:dataTable>
<h:column>
<h:panelGroup rendered="#{expression which returns true}">
<f:verbatim rendered="#{someView.agentEdit}"> </f:verbatim>
<h:commandLink id= "editId" styleClass="commandLinkClass"rendered="#policyHistory.agentEdit}" onclick="performPolicyHistoryAction('Edit', id); return false;" value="Edit"/>
</h:panelGroup>
</h:column>
</h:dataTable>
工作正常......
答案 1 :(得分:0)
非常感谢你的回答,这对我很有帮助。在我的例子中,我在Jquery的命令按钮中调用了click()动作。所有这些都来自输入类型图像。但是页面只在提交时刷新了chrome,并且从未在托管bean中调用datosTraficoJS,因此页面永远不会重定向到下一个页面。只有在Chrome和IE中不起作用,FF运行良好。 我把&#34 ;;返回false&#34;在onclick之后,它运作良好。
输入类型:
<input type="image" src="../resources/clock.png" onclick="editaTrafico(401); return false;"/>
功能:
function editaTrafico(idEmbarque) {
var fieldIdEmbarque = $("#consultaDespachosTraficoForm\\:hdnIdEmbarque");
fieldIdEmbarque.val(idEmbarque);
var botonTraf = $("#consultaDespachosTraficoForm\\:hdnBtn");
botonTraf.click();
}
命令按钮:
<h:commandButton id="hdnBtn" type="submit" action="#consultaDespachosTraficoBean.datosTraficoJS}"
value="#{msg.gen_filtrar}" />
希望对其他人有帮助。