Jsf: passing data to another controller after post - Stack Overflow

In a legacy jsf application viewA (xhtnl page) uses controllerA, viewB uses controllerB. Both controlle

In a legacy jsf application viewA (xhtnl page) uses controllerA, viewB uses controllerB. Both controllers are session scoped.

I have to add new functionality and a post on viewA should display viewB initialized with some data from controllerA. I tried with f:viewaction but it is executed only for get requests.

Maybe I could try with c:set or I could inject controllerA into controllerB but I'm searching for a cleaner solution.

Update

As stated above I unsuccessfully tried to pass data with f:viewaction but I fot to mention that I intended to use Post redirect get pattern. Unfortunately in the post action I wrote something like viewB?faces_redirect=true. I didn't noticed that damn underscore was wrong

In a legacy jsf application viewA (xhtnl page) uses controllerA, viewB uses controllerB. Both controllers are session scoped.

I have to add new functionality and a post on viewA should display viewB initialized with some data from controllerA. I tried with f:viewaction but it is executed only for get requests.

Maybe I could try with c:set or I could inject controllerA into controllerB but I'm searching for a cleaner solution.

Update

As stated above I unsuccessfully tried to pass data with f:viewaction but I fot to mention that I intended to use Post redirect get pattern. Unfortunately in the post action I wrote something like viewB?faces_redirect=true. I didn't noticed that damn underscore was wrong

Share Improve this question edited Mar 13 at 16:23 Filippo asked Mar 12 at 11:51 FilippoFilippo 1,1731 gold badge12 silver badges30 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

There are 2 problems:

  • Beans associated with views are session scoped instead of view scoped. This is not the correct practice as per How to choose the right bean scope?
  • Target page is opened by (POST) navigation instead of (GET) redirect. This is not the correct practice as per How to navigate in JSF? How to make URL reflect current page (and not previous one)

This causes that you cannot open and initialize the target page idempotently.

If you cannot fix these 2 problems, then your best bet is really to simply inject one bean in another and trigger some initialization. You need to inject the bean of the target page (controllerB) into the bean where the action is invoked and then pre-initialize the bean of the target page in the action method, before navigating.

public String submitAndNavigateToViewB() {
    controllerB.performInitializationFromControllerA(passingDataFromViewA);
    return "viewB";
}

But again, following the correct practices is better in long term. See the two links posted above.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744754557a4591801.html

相关推荐

  • Jsf: passing data to another controller after post - Stack Overflow

    In a legacy jsf application viewA (xhtnl page) uses controllerA, viewB uses controllerB. Both controlle

    10小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信