When using <p:rowEditor>, how can I retrieve the row index of the edited cell?
Here is the relevant code:
<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>
In simple datatables I used to use the <f:param> in a <p:commandLink> as follows:
<f:param name="index" value="#{rowIndex}" />
However, in my case with <p:rowEditor>, how can I get the row index when the user validates the edited value in the onParameterValueEdit() method?
public void onParameterValueEdit(RowEditEvent event) {
int index = ... // index of the row to which the edited cell belongs
parametersValue.set(Integer.parseInt(index),paramValue);
}
This design makes no sense. Just bind the component value to the
parametersValuelist directly.This way you also don’t need to know about the row index anymore and you perhaps also don’t need those action listener methods anymore. I’d only rename the property name to
parameterValuesto fix improper English.Unrelated to the concrete problem, even though you aren’t using any validation here, but since you mentioned the word “validate”, I’d like to add that that validation should be performed by normal validators, not by action(listener) methods. Use the
requiredorvalidatorattribute, or the<f:validator>or<f:validateXxx>tags.