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
}
BUT
My AJAX update does not reload the
Code: Select all
<h:selectOneMenu id="selVacinador" />
Code: Select all
<f:selectItems value="#{edicaoAplicacaoVacinaBean.listaVacinadores}" />
Code: Select all
public List<VacinadorModel> getListaVacinadores() { return listaVacinadores; }
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"/>
Code: Select all
update="@form:dtVacinacoes:@row(#{rowIdx}) :messages"/>
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
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>
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