I’m trying to use dataModel instead of binding dataTable and have this issue. At the last column there is a commandButton which should be used for delete item from database. But when I press it, the java method isn’t started.
Part of xhtml (reduced code):
<h:form>
<rich:extendedDataTable
id="table"
var="fItem"
value="#{myFood.model}"
selectionMode="none">
<rich:column width="150px">
<f:facet name="header">Datum:</f:facet>
<h:outputText value="#{fItem.date}"/>
</rich:column>
<rich:column>
<h:commandButton id="save" action="#{myFood.delete}" value="delete"/>
</rich:column>
<f:facet name="footer">
<h:commandButton id="btnTest" action="#{myFood.test}" value="test"/>
</f:facet>
</rich:extendedDataTable>
</h:form>
Part of MyFood.java:
public void delete()
{
System.out.println("TEST");
try
{
DaoCrud.delete(model.getRowData(), 'P');
}
catch (Exception e) {.....}
}
public void test()
{
System.out.println("TEST");
}
But even “TEST” is not writen to console!
Where could be the problem?
UPDATE: I’ve updated code examples (facet & test()), it works. Everything works fine until I’ve tried using dataModel private DataModel<Item> model;…
When I simply move the same commandButton to the facet, it works.
If the bean is request scoped, then you need to ensure that exactly the same model is been created during bean’s (post)construction of the form submit request as it was during displaying the initial form.
JSF will namely iterate over the model during the apply request values phase to determine the button pressed so that it can be invoked during the invoke application phase.
If preserving the model in the subsequent request isn’t exactly trivial due to some business restrictions (e.g. missing parameters, etc), then you need to put the bean in the view scope by marking it
@ViewScopedinstead of@RequestScoped. This works only if you’re using JSF 2.0.Alternatively, since you’re using RichFaces, you could also use
<a4j:keepAlive>for this. Put this somewhere in the same page as the form:This does effectively the same as
@ViewScopeddoes in JSF 2.0.