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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744754557a4591801.html
评论列表(0条)