Primefaces RowToggle - How to differentiate between Row Expansion and Row Collapse?

北城余情 提交于 2020-01-04 15:18:12

问题


I am using Prmefaces 3.5. I use the RowToggler in a datatable. Whenever the RowToggle button is clicked, I use to do some database access operations and display a grid with the the accessed data.

Whenever the toggle button is clicked the below listener is called, in which the operations are done

<p:ajax event="rowToggle" listener="#{controller.onRowToggle}" 

But the problem lies in calling this method. Not only when the row is expanded, this method is called, but also when the row is collapsed. The database operations doesn't need to be done while the row is collapsed, and so this is turning out to be an expensive operation.

Please suggest how to know if the row is expanded or collapsed, so I could do the operations conditionally?


回答1:


Have you tried using ToggleEvent#getVisibility() metod in your listener? Here's example:

public void onRowToggle(ToggleEvent event) {
    if (event.getVisibility() == Visibility.VISIBLE) {
        // your code here
    }
}



回答2:


If you want to make the RT only if the row is being expanded, this will work:

<p:ajax
    event="rowToggle"                                            
    onstart="return cfg.ext.params[0].name.indexOf('_rowExpansion') != -1"
    listener="#{fooViewModel.onRowToggle}"
/>


来源:https://stackoverflow.com/questions/23856083/primefaces-rowtoggle-how-to-differentiate-between-row-expansion-and-row-collap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!