I use a datatable to persist in a database.
And it works very well!
My problem occurs when I persist my data.
If I throw an exception because my data does not satisfy the constraints, my datatable still appears with the change.
How can I keep in cell-editing?
Or how to display the value of the database (which has not been updated) instead of those that have just been validated (which is wrong).
This is my code
Code: Select all
<h:form>
<p:dataTable var="typeSpectacles" value="#{typeSpectaclesController.typesSpectacles}" rowEditListener="#{typeSpectaclesController.rowEdit}" onRowEditUpdate="msgs" >
<p:column headerText="Code" style="width:70px">
<h:outputText value="#{typeSpectacles.code}" />
</p:column>
<p:column headerText="Libellé">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{typeSpectacles.libelle}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{typeSpectacles.libelle}" style="width: 100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Opts" style="width:50px">
<p:rowEditor />
</p:column>
</p:dataTable>
</h:form>
Code: Select all
public void rowEdit(RowEditEvent ev) {
TypeSpectacles obj = null;
try {
obj = (TypeSpectacles) ev.getObject();
ejb.edit(obj);
} catch (Exception ex) {
addMessage(ex);
}
}
Thank you!