[英]How to update a specific cell on a PrimeFaces dataTable
In my dataTable
I am linking each article with a specific task. 在我的
dataTable
我将每篇文章与特定任务相关联。
On the click of a commandButton
a list of tasks shows up, so I want on the select of a task, update a specific cell in the dataTable
( outputText
with id="columnTache"
) without updating the rest of my dataTable
. 在单击
commandButton
显示一个任务列表,所以我想选择一个任务,更新dataTable
的特定单元dataTable
( outputText
, id="columnTache"
),而不更新我的dataTable
的其余部分。
<p:dataTable value="#{myController.articleList}"
id="tabArticle"
var="article"
rowKey="#{article.id}" >
<p:column headerText="quantite" >
<pe:inputNumber value="#{article.quantite}" />
</p:column>
<p:column headerText="taches" >
<h:outputText value="#{article.tache.libelleTache}" id="columnTache" />
</p:column>
<p:column headerText="taches" >
<p:commandButton oncomplete="PF('dialogTasks').show();" update=":formSelectAffecterTache">
<p:ajax event="click" listener="#{myController.setArticle(article)}" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:dialog header="#{bundleTech.lbl_taches}" widgetVar="dialogTasks" >
<h:panelGrid columns="1" >
<h:form id="formSelectAffecterTache">
<ui:include src="/pages/listTacheSelect.xhtml">
<ui:param name="bean" value="#{myController}" />
<ui:param name="action" value="affecterTache" />
</ui:include>
</h:form>
</h:panelGrid>
</p:dialog>
The update of my dataTable
is in the managed bean: 我的
dataTable
的更新在托管bean中:
public void affecterTache() {
article.setTache(selectedSingleTache);
RequestContext.getCurrentInstance().update("form:tabArticle");
}
A dataTable
is a naming container, so components within it will be prepended with the dataTable
's id
. dataTable
是一个命名容器,因此其中的组件将以dataTable
的id
为前缀。 Also, each iteration of data presented in the table (each row) will have effect of the generated id
s. 此外,表(每行)中呈现的每次数据迭代都将影响生成的
id
。 Since a form is also a naming container, your outputText
component id
s will be generated as formId:tabArticle:0:columnTache
in the first row, formId:tabArticle:0:columnTache
in the second row, etc. 由于表单也是命名容器,因此您的
outputText
组件id
将生成为formId:tabArticle:0:columnTache
第一行中的formId:tabArticle:0:columnTache
, formId:tabArticle:0:columnTache
第二行中的formId:tabArticle:0:columnTache
等。
If you would set an id
on your commandButton
you will get formId:tabArticle:0:myButton
, formId:tabArticle:1:myButton
etc. You can use this id
in your click handler to create the corresponding inputText
clientId
. 如果你要在
commandButton
上设置一个id
,你将获得formId:tabArticle:0:myButton
, formId:tabArticle:1:myButton
等。你可以在你的点击处理程序中使用这个id
来创建相应的inputText
clientId
。 But, since you pass article
to a method, you are not able to check which button was clicked. 但是,由于您将
article
传递给方法,因此您无法检查单击了哪个按钮。 So first of all change the click listeners method to: 首先,将click侦听器方法更改为:
public void useArticle(AjaxBehaviorEvent event) {
UIComponent component = event.getComponent();
}
Now, you know which button was clicked ( event.getComponent()
), but you need your article
as well. 现在,您知道单击了哪个按钮(
event.getComponent()
),但您也需要您的article
。 You can set that as an attribute to your button in XHTML: 您可以将其设置为XHTML中按钮的属性:
<p:commandButton id="myButton"
oncomplete="PF('dialogTasks').show();"
update=":formSelectAffecterTache">
<p:ajax event="click"
listener="#{myController.useArticle}" />
<f:attribute name="article"
value="#{article}" />
</p:commandButton>
This attribute can be read in your listener: 可以在侦听器中读取此属性:
Article article = (Article) component.getAttributes().get("article");
Now, for updating the inputText
, simply use the button's clientId
: 现在,要更新
inputText
,只需使用按钮的clientId
:
String update = component.getClientId().replace(":myButton", ":columnTache");
Store it in your bean, and when you are ready to do so, update: 将它存储在bean中,当您准备好这样做时,请更新:
RequestContext.getCurrentInstance().update(update);
See also: 也可以看看:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.