admin管理员组文章数量:1391964
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 badges1 Answer
Reset to default 2There 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.
本文标签: Jsf passing data to another controller after postStack Overflow
版权声明:本文标题:Jsf: passing data to another controller after post - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744754556a2623382.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论