JSF:MyFaces CODI 类型安全导航和 f:viewParam

发布于 2024-11-28 01:04:13 字数 894 浏览 2 评论 0原文

我正在尝试 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉殇 2024-12-05 01:04:13

他们实现了您正在寻找的东西。请参阅https://issues.apache.org/jira/browse/EXTCDI-216

They implemented what you are looking for. See https://issues.apache.org/jira/browse/EXTCDI-216

恋竹姑娘 2024-12-05 01:04:13

@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 的重构功能。这样,只有参数不会是类型安全的...

我建议您使用 标记,这样您就不必像这样走过槽了

String viewParam = "";
for (UIComponent comp : event.getComponent().getChildren()) {
   if (comp instanceof UIParameter ) {
      UIParameter myParameter = (UIParameter) comp;
    if (myParameter.getName().equals("myParameterName")) {
        viewParam = myParameter.getValue());
    }
}
}
// add your viewParam to the navigation string here

这里的缺点是代码深处某处参数的硬编码名称。因此,一旦 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 this

String viewParam = "";
for (UIComponent comp : event.getComponent().getChildren()) {
   if (comp instanceof UIParameter ) {
      UIParameter myParameter = (UIParameter) comp;
    if (myParameter.getName().equals("myParameterName")) {
        viewParam = myParameter.getValue());
    }
}
}
// add your viewParam to the navigation string here

The 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文