I have to create a datatable component (as Backing Component).
The pagination (<h:commandLink>
outside of <h:dataTable>
) and sorting (<h:commandLink>
in <f:facet name="header">
) works fine. But now i would like to add a delete function for each row. Some part of my code in my faclet(<cc:implementation>
) looks like this:
<h:form id="form">
<h:dataTable id="table" value="#{cc.paginationPage.listings}" var="user">
<h:column>
<f:facet name="header">Delete</f:facet>
<h:commandLink id="btn">
<span>X</span>
<f:param value="#{cc.paginationPage.sortedColumn}" name="sorting_column"/>
<f:param value="#{cc.paginationPage.sortedColumnDirection}" name="sorting_direction"/>
<f:param value="#{cc.paginationPage.currentPage}" name="pagination_page"/>
<f:param value="#{user.id}" name="user_id"/>
<f:ajax execute="@form" event="click" render="@form" listener="#{cc.delete}" />
</h:commandLink>
</h:column>
</h:dataTable>
</h:form>
cc.delete
is a function in my bean (FacesComponent) and looks like this:
public void delete(AjaxBehaviorEvent event) {
System.out.println("delete!");
}
The problem is that listener
in <f:ajax>
is ignored. The ajax calls only the init function in the bean (set with <f:event listener="#{cc.init}" type="preRenderView"></f:event>
). There's no error or exception. Even if i try to call something like listener="#{cc.doesentExist}"
.
I believe my problem is in point 4. of BalusC's list (same like kavain's problem in the comments).
But i dont know how to fix it, cos i dont can change my bean to ViewScoped. So, how can I get the <h:commandLink>
working in this scenario? Could anyone please help me?
PS: Unfortunately i can only use plain JSF (2.3) (no frameworks like primefaces etc. allowed).
Thanks!
If i add a binding to the <h:datatable> and set the value of the <h:datatable> in the init() function in facescomponent, quite similar like in this example it works, but im not sure if this is the way to go, but it worked.