PrimeFaces datatable.filter() and url parameter

2019-08-08 02:17发布

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条回答
forever°为你锁心
2楼-- · 2019-08-08 02:48

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:

查看更多
登录 后发表回答