开发者

JSF: MyFaces CODI typesafe navigation and f:viewParam

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!


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


@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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜