Does f:viewParam only pass query string in url when first page uses the same managed bean as the second page?

╄→尐↘猪︶ㄣ 提交于 2019-11-30 15:45:52
BalusC

includeViewParams works only if both the source and target view have the desired view parameters declared as <f:viewParam>.

So, in your parituclar case, you need to put the <f:viewParam>s with very same name in both the search.xhtml and results.xhtml. Under the covers, the includeViewParams namely only grabs the view params of the current view and then only applies the ones which are also declared in the target view.

See also:


Unrelated to the concrete problem, you seem to effectively want a GET form. In that case, there is a better way for that than performing a POST-Redirect-GET with parameters. Look at the bottom of the above "See also" link.

I suggest you to implement two @ViewScoped managed beans, one for the search page and the other for the results page. You should also have two xhtml pages, each one related with a bean. Obviusly its page will have its own url (as it seems you're doing right now with the same bean).

You can make the second page's bean expect two parameters, firstName and lastName. After, in the preRenderView method, when parameters are already set into the second managed bean, query your DB with that values. So how to achieve the transition between the beans? An outcome should be enough.

<p:button outcome="results">
    <f:param name="firstName" value="#{searchBean.firstName}">
    <f:param name="lastName" value="#{searchBean.lastName}">
</p:button>

This makes JSF build an url with the params you need. After you can do exactly the same that you're doing right now, but using your second bean to get your params (I strongly suggest you not to use a getter method for the preRenderView method):

<f:metadata>
  <f:event type="preRenderView" listener="#{resultBacker.initialize}" />
  <f:viewParam name="firstName" value="#{resultBacker.firstName}"/>
  <f:viewParam name="lastName" value="#{resultBacker.lastName}"/>
</f:metadata>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!