【问题标题】:Not able to call jsf action through h:commandbutton in chrome无法通过 chrome 中的 h:commandbutton 调用 jsf 操作
【发布时间】:2014-06-25 13:28:21
【问题描述】:

对 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 被声明为

&lt;h:commandButton action="#{someBean.viewOnlyAction}"
        id="lnkViewOnlyrefresh" value="refresh" styleClass="hide" title="refresh"&gt;&lt;/h:commandButton&gt;

在 chrome 中,不调用 commandButton 的 action 方法。它在 IE 和 FF 中运行良好

注意:如果我将警报放在 的 onClick 中,我会收到警报。

【问题讨论】:

  • 上面的代码在哪里?
  • 对不起,因为我第一次在这里发布的代码放置不当,现在你可以看到代码:)

标签: javascript google-chrome jsf-1.1


【解决方案1】:

改为onclick="return performPolicyHistoryAction('ViewOnly', id);"改为 onclick="performPolicyHistoryAction('ViewOnly', id); return false;"

在下面的代码中

<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>

工作正常...

【讨论】:

    【解决方案2】:

    非常感谢您的回答,这对我很有帮助。在我的情况下,我在 Jquery 的命令按钮中调用 click() 操作。所有这些都是从输入类型的图像调用的。但是页面仅在提交时刷新在 chrome 中,并且从未在托管 bean 中调用 datosTraficoJS,因此页面永远不会重定向到下一个。仅在 chrome 和 IE 中不起作用,FF 运行良好。 我在 onclick 后加上“;return false”,效果很好。

    输入类型:

    <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}" />
    

    希望对其他人有所帮助。

    【讨论】:

      猜你喜欢
      • 2011-04-17
      • 2012-07-06
      • 1970-01-01
      • 2010-12-01
      • 2013-06-26
      • 2013-09-04
      • 2014-02-25
      • 2013-07-18
      • 1970-01-01
      相关资源
      最近更新 更多