PrimeFaces rowIndexVar in a DataTable

UI Components for JSF
Post Reply
DGorges
Posts: 2
Joined: 11 May 2021, 18:47

11 May 2021, 19:46

Hi, everyone.

I've passed throught this situation last week:

We have made this dataTable where we need some back bean method will be called when the user clicks on edit icon.
This method will make a database's call to get the list using a parameter from the dataTable's line.

Code: Select all

<h:form id="form">
	<p:outputPanel id="opVacinacoes">
		<div class="row">
			<div class="col-md-12">
				<p:dataTable id="dtVacinacoes" var="vacinacao" editMode="row"
					value="#{edicaoAplicacaoVacinaBean.listaVacinacoes}"
					editable="true" rowIndexVar="rowIdx">

					<p:ajax event="rowEditInit" process="@this"
						listener="#{edicaoAplicacaoVacinaBean.onRowEditInit}"
						update="@form:dtVacinacoes:#{rowIdx}:selVacinadores :messages"/>
					<p:ajax event="rowEdit"
						listener="#{edicaoAplicacaoVacinaBean.onRowEditSave}"
						update="@this :messages" />
					<p:ajax event="rowEditCancel"
						update="@this :messages" />

					<!--  Other columns -->

					<p:column headerText="#{msgVAC['Vacinacao.dsVacinador']}"
						width="10%">
						<div>
							<p:cellEditor>
								<f:facet name="output">
									<h:outputText value="#{vacinacao.vacinador.dsVacinador}" />
								</f:facet>
								<f:facet name="input">
									<h:selectOneMenu value="#{vacinacao.vacinador}" id="selVacinador"
										style="width:100%" converter="entityConverter">
										<f:selectItems 
											value="#{edicaoAplicacaoVacinaBean.listaVacinadores}"
											var="vacinador" itemLabel="#{vacinador.dsVacinador}"
											itemValue="#{vacinador}" />
									</h:selectOneMenu>
								</f:facet>
							</p:cellEditor>
						</div>
					</p:column>

					<!--  Other columns -->
					
					<p:column style="width:6rem">
						<p:rowEditor editTitle="#{msg['gen.editar']}"
							cancelTitle="#{msg['gen.cancelar']}"
							saveTitle="#{msg['gen.salvar']}" />
					</p:column>
				</p:dataTable>
			</div>
		</div>
	</p:outputPanel>
</h:form>

Code: Select all

	public void onRowEditInit(RowEditEvent event) {
		// code
	}
When we have that code, almost everything works fine: the method is called, the parameter is getted and the list was refreshed..
BUT
My AJAX update does not reload the

Code: Select all

<h:selectOneMenu id="selVacinador" />
whit the fresh list to populate

Code: Select all

<f:selectItems value="#{edicaoAplicacaoVacinaBean.listaVacinadores}" />
On debug mode, we could see the

Code: Select all

public List<VacinadorModel> getListaVacinadores() { return listaVacinadores; }
was not called.

After some analysis, we realise a conclusion:
- On the moment when method is called and the update was invoked, the 'rowIdx' was not loaded yet. He are null.

If whe change

Code: Select all

update="@form:dtVacinacoes:#{rowIdx}:selVacinadores :messages"/>
to

Code: Select all

update="@form:dtVacinacoes:@row(#{rowIdx}) :messages"/>
we got a Exception:

Code: Select all

Expression does not match following pattern @row(n). Expression: "@row()"

javax.faces.FacesException: Expression does not match following pattern @row(n). Expression: "@row()"
at org.primefaces.expression.impl.RowExpressionResolver.validate(RowExpressionResolver.java:98)
at org.primefaces.expression.impl.RowExpressionResolver.resolveClientIds(RowExpressionResolver.java:31)
at org.primefaces.expression.SearchExpressionFacade.resolveClientIdsByExpressionChain(SearchExpressionFacade.java:642)
at org.primefaces.expression.SearchExpressionFacade.resolveClientIds(SearchExpressionFacade.java:192)
at org.primefaces.util.AjaxRequestBuilder.addExpressions(AjaxRequestBuilder.java:93)
at org.primefaces.util.AjaxRequestBuilder.update(AjaxRequestBuilder.java:86)
...
Caused by: javax.faces.FacesException: Expression does not match following pattern @row(n). Expression: "@row()"
at org.primefaces.expression.impl.RowExpressionResolver.validate(RowExpressionResolver.java:94)
... 69 more
That exception we got because de 'rowIdx' is null. As we can see on https://github.com/primefaces/primeface ... olver.java

But, when we build a test including a column on dataTable like this

Code: Select all

<p:column headerText="#{msgVAC['Vacinacao.nrDose']}">
	<h:outputText value="#{rowIdx}" />
</p:column>
The row was printed with the Index correctly.

So, my question is:
Why the attribute dataTable.rowIndexVar was not loaded yet when we execute the AJAX call?

Thanks for all who spent a time to get some help.

I`m using Primefaces 6.1 and JSF 2.2
Primefaces 6.1 / JSF 2.2

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

12 May 2021, 13:36

I don't think you can update="" a single row like that. I could be wrong but I don't think it works like that.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

DGorges
Posts: 2
Joined: 11 May 2021, 18:47

12 May 2021, 19:34

Melloware wrote:
12 May 2021, 13:36
I don't think you can update="" a single row like that. I could be wrong but I don't think it works like that.
I think we could, because if whe do this:

Code: Select all

update="@form:dtVacinacoes:0:selVacinadores
or this

Code: Select all

update="@form:dtVacinacoes:row(0)
or even this

Code: Select all

update="@this
the row, and just that row, was updated.

But, in this case, the rows update turn the 'edit' mode from PF off.
Primefaces 6.1 / JSF 2.2

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 55 guests