Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 选择表行时启用JSF Primefaces set按钮_Javascript_Jsf_Primefaces - Fatal编程技术网

Javascript 选择表行时启用JSF Primefaces set按钮

Javascript 选择表行时启用JSF Primefaces set按钮,javascript,jsf,primefaces,Javascript,Jsf,Primefaces,我有一个表中的用户列表,并且禁用了删除按钮。我需要在选择表中的行时启用“删除”按钮。我该怎么做 <p:dataTable value="#{userBean.patients}" var="item" selectionMode="single" rowKey="#{item.id}" selection="#{userBean.selected}" onRowSelected="deleteButton.disabled='false';"

我有一个表中的用户列表,并且禁用了删除按钮。我需要在选择表中的行时启用“删除”按钮。我该怎么做

<p:dataTable value="#{userBean.patients}" var="item"
            selectionMode="single" rowKey="#{item.id}"
            selection="#{userBean.selected}"
onRowSelected="deleteButton.disabled='false';"> // HOW TO WRITE THIS EVENT CORRECTLY?????
// columns
</p:dataTable>
//This button must be enable after I click on any table row
<p:commandButton id="deleteButton" value="Delete" disabled="true" />
//如何正确写入此事件?????
//纵队
//单击任何表格行后,必须启用此按钮

也许,我需要使用onRowClick事件。我不知道此事件的名称

一个解决方案可能正在使用

在数据表内部

这将捕获行选择事件,调用侦听器并更新按钮

现在,您可以在支持bean中定义侦听器,该侦听器只更新布尔实例变量的值,该变量反映视图中按钮的禁用/启用状态:

您可以在primefaces showcase中查看类似场景:

希望这有帮助。

感谢jsfviky71! 我写道:


希望这将有助于其他人提供您尝试过的代码。选择行时,必须设置
enable=true
update
delete按钮。有几种方法可以选择PF数据表中的行。请告诉/展示你是如何做到这一点的。只有这样,我们才能知道如何用这种方式钩住侦听器
<h:form id="form">
<p:dataTable value="#{bean.patients}" var="item"
            selectionMode="single" rowKey="#{item.id}"
            selection="#{bean.selected}" >
     <p:ajax event="rowSelect" update=":form:deleteButton" listener="#{bean.onRowSelect}" />
 // data in rows
</p:dataTable>

<p:commandButton id="deleteButton" value="Delete" disabled="#{bean.disabled}"/>
private Boolean disabled = true;

// getter and setter

public void onRowSelect(SelectEvent event) {
    disabled = false;
}