PrimeFaces datatable.filter()和url参数 [英] PrimeFaces datatable.filter() and url parameter
问题描述
我有一个可在其中使用primeface的.xhtml模型。
我用这样的URL调用页面:
http:// localhost:8080 / myproject / mypage.jsf?Id = 51& startDate = 04-05-2015& name = whatever
URL参数用于检索将显示在数据表中的内容,因此它允许我过滤内容。
我使用了URL参数,因为当我在另一个datable中选择一行时,显示这个页面,所以我必须在烘焙bean上手动重定向到这个页面。然而,每次我使用排序或分页等primeface功能之一,primeface似乎做一个ajax调用的支持bean,但没有参数,所以每个对象都显示,而不是过滤的对象列表。
因此,如何强制primefaces使用这些参数?或者如何将它们传递给primefaces作用域(它们是支持bean上的@ManagedProperty)
最好和最简单的方法是要使用 OmniFaces实用程序库,更具体地说是使用 < o:form>
。
从文档:
< o:form>
是一个组件扩展了标准的< h:form>
,并提供了一个方法来在请求URL中保留视图或请求参数后面的
您可以像
< h:form>
,您只需将h:
更改为o:
。所以,把你的< h:form>
替换成 p>
< o:form includeRequestParams =true>
或
< o:form useRequestURI =true>
另请参阅:
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)
解决方案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:
这篇关于PrimeFaces datatable.filter()和url参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!