Datatable row expansion event

Renju picture Renju · Jul 18, 2011 · Viewed 20.7k times · Source

I am using Primefaces 3.0 with JSF 2.0. I have a datatable with expansion enabled. I wanted to call a bean method when the user clicks on rowToggler. Basically I wanted to load the expansion details only when the user clicks the expand button. I can't see a server side callback for row expansion in the documentation. Please let me know if I can have any workaround for this problem.

Thanks and Regards, Renju

Answer

jimmybondy picture jimmybondy · Jul 15, 2013

Following the link Howard provided in the question comment I could see that this was implemented in PF 3.4:

XHTML

<p:ajax event="rowToggle" listener="#{tableBean.onRowToggle}" update=":form:growl" />

Bean

public void onRowToggle(ToggleEvent event) {
    FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO,
                                        "Row State " + event.getVisibility(),
                                        "Model:" + ((Car) event.getData()).getModel());

    FacesContext.getCurrentInstance().addMessage(null, msg);
}

You can see this in the showcase: https://www.primefaces.org/showcase/ui/data/datatable/expansion.xhtml