首页 > 解决方案 > 单击表格行中的项目时,如何防止执行默认的 onRowClick 操作?

问题描述

在基于 Seam 2.2、jsf 1.2 和 Richfaces 3.3 的遗留应用程序中,我遇到了 Internet Explorer 问题:

我有一个带有可点击行的数据表。单击一行将打开该项目的详细视图。最后一列包含一个垃圾桶图标。单击该图标时,将出现一个确认对话框。如果未确认,则不会发生其他任何事情。这在谷歌浏览器上运行良好。

它不适用于 Internet Explorer(在版本 11 上测试)。在这里,执行默认操作action="#{myAction.select(k)}"。我尝试添加event.preventDefault();event.stopPropagation();但没有帮助。

我怎样才能让它在 Internet Explorer 上工作?

<rich:dataTable id="myDatatable" value="#{list.model}" var="k"
                headerClass="tableheader"
                onRowMouseOver="this.style.backgroundColor='#F1F1F1'"
                onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
                rowClasses="clickableRow">
    <a4j:support event="onRowClick" id="onRowClickEvent"
                 action="#{myAction.select(k)}"
                 reRender="myDatatable"/>

    <rich:column>
        <f:facet name="header">
            <a4j:commandLink action="#{list.changeOrder('k.name')}" 
                    value="Name #{list.orderColumn == 'k.name' ? (list.orderAscending ? '▲' : '▼') : ''}"
                    reRender="myDatatable" ajaxSingle="true" limitToList="true"/>
        </f:facet>
        <h:outputText value="#{k.name}"/>
    </rich:column>

    <rich:column style="text-align: center;">
        <f:facet name="header">
            <a4j:outputPanel layout="block">
                <h:outputText value="Delete"/>
            </a4j:outputPanel>
        </f:facet>

        <a4j:outputPanel onclick="event.preventDefault();event.stopPropagation();">
            <s:graphicImage value="/img/bin_closed.gif" style="cursor: pointer;">
                <a4j:support event="onclick"
                             action="#{myAction.delete(k)}"
                             ajaxSingle="true" limitToList="true"
                             onsubmit="if(!confirm('Are you sure?')) { return false; }" />
            </s:graphicImage>
        </a4j:outputPanel>
    </rich:column>

</rich:dataTable>

标签: javainternet-explorerrichfacesseamajax4jsf

解决方案


我能够通过替换为这个问题的答案中描述的来解决event.preventDefault();event.stopPropagation();问题Event.stop(event);停止 JSF 事件链,prageeth 回答


推荐阅读