[英]How to update a specific cell on a PrimeFaces dataTable
在我的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>
我的dataTable
的更新在托管bean中:
public void affecterTache() {
article.setTache(selectedSingleTache);
RequestContext.getCurrentInstance().update("form:tabArticle");
}
dataTable
是一个命名容器,因此其中的组件将以dataTable
的id
为前缀。 此外,表(每行)中呈现的每次数据迭代都将影响生成的id
。 由于表单也是命名容器,因此您的outputText
组件id
将生成为formId:tabArticle:0:columnTache
第一行中的formId:tabArticle:0:columnTache
, formId:tabArticle:0:columnTache
第二行中的formId:tabArticle:0:columnTache
等。
如果你要在commandButton
上设置一个id
,你将获得formId:tabArticle:0:myButton
, formId:tabArticle:1:myButton
等。你可以在你的点击处理程序中使用这个id
来创建相应的inputText
clientId
。 但是,由于您将article
传递给方法,因此您无法检查单击了哪个按钮。 首先,将click侦听器方法更改为:
public void useArticle(AjaxBehaviorEvent event) {
UIComponent component = event.getComponent();
}
现在,您知道单击了哪个按钮( event.getComponent()
),但您也需要您的article
。 您可以将其设置为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>
可以在侦听器中读取此属性:
Article article = (Article) component.getAttributes().get("article");
现在,要更新inputText
,只需使用按钮的clientId
:
String update = component.getClientId().replace(":myButton", ":columnTache");
将它存储在bean中,当您准备好这样做时,请更新:
RequestContext.getCurrentInstance().update(update);
也可以看看:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.