我的数据表有问题,我想在选择时显示数据表行的信息,因为我创建了一个名为currentChangerStatus的值我想将它设置为当前选择,这是我的代码:
<p:dataTable id="projets" var="p" value="#{projet.init()}" rowSelectListener="#{projet.currentChangerStatus(currentChangerStatus)}" selectionMode="single" onRowSelectStart="datecreation">
<f:facet name="header">
Listes des projets Gpsi
</f:facet>
<p:column>
<f:facet name="header">
<h:outputText value="Code" />
</f:facet>
<h:outputText value="#{p.projets.codeProjet}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Intitulé" />
</f:facet>
<h:outputText value="#{p.projets.libelle}" />
</p:column>
</p:dataTable>
豆子:
public void setCurrentChangerStatus(ChangerStatus currentChangerStatus)
{
this.currentChangerStatus=currentChangerStatus;
}
public ChangerStatus getCurrentChangerStatus()
{
return currentChangerStatus;
}
问题是datable不接受这个表达式:
rowSelectListener="#{projet.currentChangerStatus(currentChangerStatus)}"
答案 0 :(得分:2)
这是显示数据表行信息的另一种方法。
<p:dataTable>
.....
.....
<p:column>
<p:commandLink update="xhtmlElementID" title="View Detail" >
<p:graphicImage value="/images/search.png" />
<f:setPropertyActionListener value="#{p}" target="#{project.SomeObject}" />
</p:commandLink>
</p:column>
</p:dataTable>
此处target =“#{project.SomeObject}”是您在命令链接上查看时要更新的数据
答案 1 :(得分:1)
我认为你正在以错误的方式使用行选择。属性rowSelectListener
需要指向具有此签名的方法(对于Primefaces showcase):
public void onRowSelect(SelectEvent event) { ... }
在p:dataTable
中,您需要以这种方式参考此方法:
<p:dataTable var="car" value="#{tableBean.cars}" paginator="true" rows="10"
selection="#{tableBean.selectedCar}" selectionMode="single"
rowSelectListener="#{tableBean.onRowSelect}"
注意如何引用侦听器方法。
通过这个,您可以在tableBean.selectedCar
中获得所选的行对象。
展示中给出了一个完整的例子(上面的链接)。
更新来自您的评论:
这是问题所在:
value="#{projet.init()}"
value属性需要引用包含数据的列表或内容,而不是方法。如果您有一个类Project,并希望在表中显示项目列表,那么您的支持bean必须包含以下内容:
private List<Project> projects;
public List<Project> getProjects() {
return projects;
}
public void setProjects(List<Project> projects) {
this.projects = projects;
}
在primefaces showcase其carSmall
列表中也是如此。