开发者

JSF: Controller that relies on another controller?

I'm working on a project where we have a FooViewController, and a BarListController. The list of Bars now needs to depend on the Foo being viewed. So does anyone have a recommendation of how to do this?

I don't need an answ开发者_如何学Pythoner from an implementation perspective, necessarily, but more from a design perspective. That is:

  • Should the FooViewController somehow tell the BarListController what Foo is being viewed?
  • Should the BarListController ask the FooViewController what Foo is being viewed?
  • In either case, how do you inject these things into one another? (This part I need implementation help ;-) )

Thanks for any help!


Basically, the bean where you're invoking the concrete action should ask for it as method argument or as managed property.

So, if you're using a Servlet 3.0 / EL 2.2 capable container, then pass Foo as method argument:

<h:commandLink value="Bar list"
    action="#{barListController.list(fooViewController.foo)}" />

with

public void list(Foo foo) {
    this.list = barService.list(foo);
}

If you're not on EL 2.2 yet, then set Foo as managed property:

<h:commandLink value="Bar list"
    action="#{barListController.list}" />

with

@ManagedBean
@ViewScoped
public class BarListController {

    @ManagedProperty("#{fooViewController.foo}")
    private Foo foo;

    public void list() {
        this.list = barService.list(foo);
    }

    // ...
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜