PrimeFaces datatable.filter() and url parameter

蹲街弑〆低调 提交于 2019-12-13 18:17:51

问题


I have a .xhtml model with a primeface datatable in it. I call the page with an URL like this: http://localhost:8080/myproject/mypage.jsf?Id=51&startDate=04-05-2015&name=whatever

The URL parameters are used to retrieve what will be displayed in the datatable, so it allow me to filter the content. I used URL parameter because this page is displayed when I select a row in another datable so I have to make a manual redirect to this page on the baking bean.

However everytime I use one of primeface functionality like sorting or pagination primeface seems to do an ajax call to the backing bean but WITHOUT the parameters, so every object are displayed instead of a filtered list of Objects.

Therefore how can I force primefaces to use these parameters? Or how can I pass them to primefaces scope (they are @ManagedProperty on the backing bean)


回答1:


The best and easiest way is to use the OmniFaces utility library and more specifically their <o:form>.

From the documentation:

The <o:form> is a component that extends the standard <h:form> and provides a way to keep view or request parameters in the request URL after a post-back

...

You can use it the same way as <h:form>, you only need to change h: to o:.

So, replace your <h:form> by either

<o:form includeRequestParams="true">

or

<o:form useRequestURI="true">

See also:

  • Retaining GET request query string parameters on JSF form submit


来源:https://stackoverflow.com/questions/30649367/primefaces-datatable-filter-and-url-parameter

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