Getting Selected Row Data from Datatable in JSF

纵然是瞬间 提交于 2019-12-04 17:02:33

the 2.0 article doesn't really address getting the selected row data

It does. Perhaps you're not looking closely enough, but it shows two ways of getting the selected row data. Look at the edit() and delete() methods of the backing bean. The first way does it by DataModel#getRowData()and the second way does it by just passing it straight into action method using the new EL 2.2 feature.


When a user clicks the "Add to my favorites" button, the selected row is not getting passed to the backing bean, the navigation case is not being followed, and the current page is refreshed.

That will happen when the value of the <h:dataTable> isn't exactly the same as it was during the initial request wherein the page with the table is been displayed. That will in turn happen if the bean is request scoped and/or the value of the <h:dataTable> depends on a request parameter. Placing the bean in the view scope and/or making sure that you prepare exactly the same value in the (post)constructor of the bean should fix it. When using the view scope, you should remove the binding of the <h:dataTable> to the bean.


In your particular case, with navigation to a different view involved, there's perhaps another, better, way. The concrete functional requirement is not exactly clear. Is it kind of a confirmation page? Rather use GET then. Or is it just a landing page after a successful action? Rather use POST-Redirect-GET. For another hints, see also Communication in JSF 2.0 - Processing GET request parameters.

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