最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论