自动在 URL 中包含视图参数
我有简单的 jsf 页面,其中包含视图参数和处理这些参数的加载方法:
<f:metadata>
<f:viewParam name="param1" value="#{bean.param1}"/>
<f:viewParam name="param2" value="#{bean.param2}"/>
<f:viewParam name="param3" value="#{bean.param3}"/>
<f:event type="preRenderView" listener="#{bean.load()}"/>
</f:metadata>
我还在 @PostConstruct
中设置了一些初始值。 如何将用户重定向到包含这些参数(不为空)的新位置。 例如,用户在浏览器中输入:
domain.com/page.jsf
并被重定向到:
domain.com/page.jsf?param1=valueA
因为 param1 是在 @PostConstruct
中设置的。
另一个问题 - 我的页面上有引用相同视图的链接:
<h:link value="clickme">
<f:param name="param3" value="otherValue"/>
</h:link>
当用户使用 ?param1=someValue
进入页面并单击链接时,被重定向到 ?param3=otherValue
但我想重定向到 ?param1=someValue¶m3=otherValue
。 我知道我可以在
中添加更多参数,但很难在每个
PS 中添加每个可能的参数。我使用本主题中的 BalusC 技巧 JSF 2 和 Post/Redirect/Get?
I have simple jsf page with view params and load method which is processing those params:
<f:metadata>
<f:viewParam name="param1" value="#{bean.param1}"/>
<f:viewParam name="param2" value="#{bean.param2}"/>
<f:viewParam name="param3" value="#{bean.param3}"/>
<f:event type="preRenderView" listener="#{bean.load()}"/>
</f:metadata>
I also set some initial values in @PostConstruct
.
How to redirect user to new location that include those parameters (which are not null).
For example user enter in browser:
domain.com/page.jsf
and is redirected to:
domain.com/page.jsf?param1=valueA
because param1 was set in @PostConstruct
.
Another question - I have links on page referencing same view:
<h:link value="clickme">
<f:param name="param3" value="otherValue"/>
</h:link>
When user enters page with ?param1=someValue
and clicks link, got redirected to ?param3=otherValue
but I want to redirect to ?param1=someValue¶m3=otherValue
.
I know I can add more parameters in <h:link>
but it's diffucult to add every possible param in every <h:link>
PS. I use BalusC tip from this topic JSF 2 and Post/Redirect/Get?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于第一个问题:您可以将
includeViewParams=true
添加到导航案例结果中。但是,当您在preRenderView
方法中执行此操作时,您永远无法保证您会成功重定向。那时可能已经太晚了。关于第二个问题:您可以将
的includeViewParams
属性设置为true
。或者,您也可以将
includeViewParams=true
添加到结果中。As to the 1st question: you can add
includeViewParams=true
to the navigation case outcome. But you can never guarantee that you'll sucessfully be redirected while you're doing that inside apreRenderView
method. It might be already too late then.As to the 2nd question: you can set the
includeViewParams
attribute of<h:link>
totrue
.Alternatively, you can also add
includeViewParams=true
to the outcome.