jsf-2 - Primefaces:单击 p:column 内的 div 时不会调用 rowSelect 方法

标签 jsf-2 primefaces

在我的 p:column 中,我有几个带有文本的 div,如果我单击文本,它不会选择该行,也不会调用 rowSelect 事件。

示例:

...
<p:column>
         text1
    <div>text2</div>
<p:column>
...

我可以单击text1,但不能单击text2。问题出在哪里?

最佳答案

问题是 div 覆盖了列的 onclick 事件。我遇到了这个问题,我的解决方案是使用以下函数覆盖 div 上的事件:

XHTML:

<p:datatable ..(properties)... widgetVar="dt" rowIndexVar"rowIndex" ...>
.......
<p:column>
   <div onclick="selectCurrentRow(dt,#{rowIndex});" > hola </div>
</p:column>
.......
<p:datatable/>

JS:

function selectCurrentRow_paginator(table,index){
table.unselectAllRows();
table.selectRow(index-(table.paginator.cfg.page*table.paginator.cfg.rows) ,false);

}

function selectCurrentRow(table,index){
table.unselectAllRows();
table.selectRow(index ,false);
}

如果 JS 说 dt 未定义,只需用 PF() 函数包围 wingetVar 名称,如下所示:

<div onclick="selectCurrentRow(PF('dt'),#{rowIndex});" > hola </div>

此解决方案也有助于 oncontextmenu 事件:

<div oncontextmenu="selectCurrentRow(PF('dt'),#{rowIndex});" onclick="selectCurrentRow(PF('dt'),#{rowIndex});" > hola </div>

关于jsf-2 - Primefaces:单击 p:column 内的 div 时不会调用 rowSelect 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21338440/

相关文章:

javascript - 如何确定是否选中了 Primefaces RadioCheckbox?

jsf - p :keyboard ajax events

forms - 仅验证表单的特定部分而不是整个表单

charts - 在 Primefaces 5.2 <p :chart jqplot-xaxis-tick 中更改字体大小

java - 下载后如何刷新页面

jakarta-ee - Java EE 6 应用程序中的 Shiro

file-upload - primefaces 显示数据库中的图像

java - JSF 通过 session 传递 POJO

java - JSF 2 - 在 <? 上隐藏默认值扩展号码>

java - JSF 2.0 : Why object in my list (except the last one) cannot be updated