在JavaServer Faces中导航,并使用正确的参数进行重定向 [英] Navigation in JavaServer Faces, redirecting with correct parameters
问题描述
我有一个页面: http://mypage.com/items.jsf .>
此页将以下内容视为理所当然:
- ID由GET设置或ID由POST设置.
现在,我可以手动调用items.jsf?ID = 10
但是我真正想做的是有一个Button,它调用一个返回导航URL的函数.
public String test()
{
return "10";
}
现在在 JSF 文件中具有以下代码.
<h:form>
<h:commandButton action="#{itemsBean.test}" value="Redirect me" />
</h:form>
我想发生的是,当我按重定向我"时,我希望导航规则知道我要去:items.jsf?ID = 10
这可能吗?感觉确实是个小问题.
仅使用核心JSF框架和Facelets库,您可能会发现这很困难. JSF 1.2库不支持将请求参数添加到重定向URL.
想到一些解决方案:
- 只需按照此处中的说明进行重定向.
- 添加您自己的自定义 NavigationHandler 和/或 ViewHandler 代码.一些第三方框架已经可以满足此类需求.例如, Seam添加了一个允许在导航规则中使用参数的pages.xml .
- 升级到 JSF2 .它增加了对导航期间处理参数的支持(并将Facelets标准化为核心API的一部分,其中包括在此处指定).在候选发布版本2 中,这可能合适,也可能不合适.
I have a page: http://mypage.com/items.jsf.
This page takes the following for granted:
- ID is set by GET or ID is set by POST.
Now, I can manually call items.jsf?ID=10
But what I really want to do is have a Button which calls a function that returns the navigation URL.
public String test()
{
return "10";
}
Now having the following code in the JSF file.
<h:form>
<h:commandButton action="#{itemsBean.test}" value="Redirect me" />
</h:form>
What I want to happen is that when I press "Redirect me", I want a Navigation-Rule to know that I want to go to: items.jsf?ID=10
Is this possible? It feels like it's a trivial problem really.
With only the core JSF framework and the Facelets library, you may find this difficult. The JSF 1.2 library does not include support for adding request parameters to the redirect URL.
A few solutions spring to mind:
- Just redirect as outlined here.
- Add your own custom NavigationHandler and/or ViewHandler code. Some 3rd party frameworks already cater for this type of thing. For example, Seam adds a pages.xml that allows parameters in navigation rules.
- Upgrade to JSF2. It adds support for handling parameters during navigation (and standardises Facelets as part of the core API, among other things - spec here). It's at release candidate 2, which may or may not suit.
这篇关于在JavaServer Faces中导航,并使用正确的参数进行重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!