在下面的示例中,如果单击一行,则会触发rowSelect-event,但如果单击该行中的图像则不会触发。
我理解为什么会发生这种情况,但我想知道是否还有一些优雅的方式来包含子组件(也可能是嵌套的子组件)?
<h:form id="form">
<p:growl id="growl" showDetail="true" />
<p:dataTable id="cars" var="car" value="#{tableBean.cars}" rows="5"
selectionMode="single">
<p:ajax event="rowSelect" listener="#{tableBean.onRowSelect}"
update=":form" />
<p:column headerText="Model">
<p:graphicImage value="myImage.png"
style="width: 40px; height: 40px;" />
</p:column>
</p:dataTable>
</h:form>
答案 0 :(得分:1)
您可以尝试在图片上添加onclick事件:
<p:dataTable rowIndexVar="rowIndex" widgetVar="scrollist"...
... onclick="scrollist.unselectAllRows(); scrollist.selectRow(#{rowIndex})"
答案 1 :(得分:-1)
只需将css添加到嵌入式img标记:
table tbody td img {pointer-events:none;
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
-o-user-select: none;
user-select: none;
}