问题
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 changeh:
too:
.
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