如何更新PrimeFaces dataTable上的特定单元格

时间:2016-03-14 14:30:58

标签: jsf primefaces datatable

在我的dataTable中,我将每篇文章与特定任务相关联。

点击commandButton显示的任务列表,我想要选择任务,更新dataTable中的特定单元格(outputText with {{ 1}})不更新我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> 的更新位于托管bean中:

dataTable

1 个答案:

答案 0 :(得分:3)

dataTable是一个命名容器,因此其中的组件将以dataTable的{​​{1}}为前缀。此外,表中(每行)中呈现的每次数据迭代都将生成id s的效果。由于表单也是一个命名容器,因此您的id组件outputText将在第一行id生成,第二行formId:tabArticle:0:columnTache等等。

如果您在formId:tabArticle:0:columnTache上设置id,则会获得commandButtonformId:tabArticle:0:myButton等。您可以在点击处理程序中使用此formId:tabArticle:1:myButton创建相应的id inputText。但是,由于您将clientId传递给方法,因此您无法检查单击了哪个按钮。首先,将click侦听器方法更改为:

article

现在,您知道点击了哪个按钮(public void useArticle(AjaxBehaviorEvent event) { UIComponent component = event.getComponent(); } ),但您也需要event.getComponent()。您可以在XHTML中将其设置为按钮的属性:

article

可以在监听器中读取此属性:

<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

将它存储在您的bean中,当您准备好这样做时,请更新:

String update = component.getClientId().replace(":myButton", ":columnTache");

另见: