【发布时间】:2012-10-23 04:55:14
【问题描述】:
使用<p:rowEditor>时,如何检索已编辑单元格的行索引?
以下是相关代码:
<p:dataTable id="datasetParamDt" var="datasetParam" value="#{projectCampaignManagementMB.allParametersList}" editable="true" rowIndexVar="rowIndex">
<p:ajax event="rowEdit" listener="#{projectCampaignManagementMB.onParameterValueEdit}" update=":campaignForm:growl" />
<p:ajax event="rowEditCancel" listener="#{projectCampaignManagementMB.onParameterValueCancel}" update=":campaignForm:growl"/>
<p:column headerText="Value">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{projectCampaignManagementMB.paramValue}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{projectCampaignManagementMB.paramValue}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Options" style="width:50px">
<p:rowEditor />
</p:column>
</p:dataTable>
在简单的数据表中,我曾经在<p:commandLink> 中使用<f:param>,如下所示:
<f:param name="index" value="#{rowIndex}" />
但是,在我使用<p:rowEditor> 的情况下,当用户在onParameterValueEdit() 方法中验证编辑的值时,如何获取行索引?
public void onParameterValueEdit(RowEditEvent event) {
int index = ... // index of the row to which the edited cell belongs
parametersValue.set(Integer.parseInt(index),paramValue);
}
【问题讨论】:
-
您究竟需要了解哪些信息?
-
等待...您的输入/输出值绑定到支持 bean,而不是数据模型的迭代行对象!这有什么意义?您应该使用
value="#{datasetParamDt.paramValue}"而不是value="#{projectCampaignManagementMB.paramValue}"。我想知道现在是否不需要了解行索引。 -
是的,这是我的问题,paramValue 不是 DataSet 类中的属性
标签: jsf primefaces