JSF:MyFaces CODI 类型安全导航和 f:viewParam
我正在尝试 MyFaces CODI 及其出色的功能。一个非常有用的东西是类型安全导航。我可以在我的控制器 bean 中指定操作方法的结果,如下所示:
public Class<? extends ViewConfig> goBack() {
return Pages.ListView.class;
}
这真的很酷,因为每个开发 IDE 都具有过度的重构能力。
但是当我想使用此功能时,我在将 viewParameter 传递到下一个视图时遇到问题。我必须使用命令按钮来调用此操作方法,如下所示:
<h:commandButton id="backButton" value="#{msgs.Button_Back}"
action="#{viewBean.goBack()}" />
如果我使用此命令按钮,我无法传递参数。一个“普通”按钮或链接就可以做到这一点:
<h:button id="backButton" value="#{msgs.Button_Back}" outcome="siteBefore.xhtml">
<f:param name="itemId" value="5" />
</h:button>
缺点是“普通”按钮不使用操作方法,因此我无法利用 CODI 类型安全导航的优势。
那么有没有可能将这两个功能结合起来呢? (传递 viewparams 并使用类型安全导航)
提前致谢!
I'm trying out MyFaces CODI with it's wonderful features. A very useful thing is the typesafe navigation. I can specify the outcome of an action method in my controller bean like this:
public Class<? extends ViewConfig> goBack() {
return Pages.ListView.class;
}
That is really cool because the excessive refactoring ability of every development IDE.
But when I want to use this feature I have a problem with passing viewParameter to the next view. I have to use a commandbutton for calling this action method like this:
<h:commandButton id="backButton" value="#{msgs.Button_Back}"
action="#{viewBean.goBack()}" />
If I use this commandbutton I cannot pass parameters. A "normal" button or a link would do it:
<h:button id="backButton" value="#{msgs.Button_Back}" outcome="siteBefore.xhtml">
<f:param name="itemId" value="5" />
</h:button>
The disadvantage is that the "normal" button don't use the action method and therefore I cannot participate on the advantage of typesafe navigation of CODI.
So is there any possibility to combine these two features? (passing viewparams and use typesafe navigation)
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
他们实现了您正在寻找的东西。请参阅https://issues.apache.org/jira/browse/EXTCDI-216
They implemented what you are looking for. See https://issues.apache.org/jira/browse/EXTCDI-216
@StevenR
CODI 在使用类型安全导航时不支持包含 viewParams,但是如果您遵循他们的问题跟踪系统,它似乎是一个前瞻性功能:
https://issues.apache.org/jira/browse/EXTCDI-171
从问题的历史记录中,您可以看出他们最近刚刚更新了状态(大约 4 周前)它可能很快就会被包括在内。也许其中一位提交者正在关注这篇文章,并且可以向我们通报这一新功能的粗略时间表吗?
此外,类型安全导航的功能已在 JSF 规范中进行了讨论:
http://java.net/ jira/browse/JAVASERVERFACES_SPEC_PUBLIC-977
作为一种解决方法,我建议按照 CODI wiki 中的提示进行操作(请参阅部分 URL下面)并使用
Pages.ListView.class.getName()
,您可以在支持 bean 的操作方法中连接其他 viewParams。这样您的导航是类型安全的,并且您可以利用 IDE 的重构功能。这样,只有参数不会是类型安全的...我建议您使用
标记,这样您就不必像这样走过槽了这里的缺点是代码深处某处参数的硬编码名称。因此,一旦 CODI 带来新功能,重构可能是值得的
cwiki.apache.org/EXTCDI/jsf-usage.html#JSFUsage-TypesafeNavigation
@StevenR
CODI does not support inclusion of viewParams when using typesafe navigation, however if you follow their issue tracking system it seems like a prospective feature:
https://issues.apache.org/jira/browse/EXTCDI-171
From the issue's history you can tell they just updated the status recently (~4 weeks ago) and it might be included soon. Maybe one of the comitters is following this post and can update us with a rough time line for this new feature?
Moreover the feature of type safe navigation has been discussed in the JSF spec:
http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-977
As a workaround I'd suggest do follow the hint in the CODI wiki (see part of the URL below) and use
Pages.ListView.class.getName()
where you could concatenate additional viewParams within your backing bean's action method. This way your navigation is type safe and you leverage your IDE's refactoring capabilities. Only the params would not be type safe this way...I would suggest you use the
<f:attribute/>
tag, so you don't have to walk trough like thisThe downside here is the hard coded name of the parameter somewhere deep inside your code. So it might be worthwhile to refactor once CODI comes with the new feature
cwiki.apache.org/EXTCDI/jsf-usage.html#JSFUsage-TypesafeNavigation