简体   繁体   中英

JSF 2.0 /CDI Scopes and Best Practises

let's assume i have the following structure:

  • pageA.xhtml - Here we can select an item which will be needed within pageB and pageC but not in pageE .

  • pageB.xhtml - Here we use the Item which was selected from pageA . We also have a selectBox and some Buttons on this page. When selecting something from the selectBox some Buttons will be deactivated and some Text can be displayed. (when refreshing this page we want the same state again). pageB includes pageD which lists some stuff. Now we can navigate to pageC . We also create some objects which are only relevant for pageC but not for other pages.

  • pageC.xhtml - here we get the object from pageB and depending on some User input we modify it and when we press apply we come back to pageB which displays our changes. From pageB we can press save which will save the changes and pageD (which is included in pageB ) will be updated.

  • pageD.xhtml - just lists some stuff. (will only included within pageB )

  • pageE.xhtml - This page will start something completely differend and does not need the input from pageA but you can navigate directly to pageC . In this case pageC has to hide some things.

I hope the example is somehow clear. Actually i just made it up to make my question a bit clearer: I want to know what the best practises are to pass data between different pages and save the actual state (also have the same state when coming back).

Also how to reset/clear data which are needed in some pages but not in different ones. For example some data will be needed for several pages but some only within nested pages (in an optimal world the data within the nested pages should be cleared when leaving them)

Of course i could save stuff i need into the session, but then i have to be careful to remove those stuff again when i don't need it anymore. JSF and CDI support Conversations. But the problem here is that it is not possible to have nested conversations. Of course i also could pass everything with request parameters .. but in this case i have to be careful if i have ajax requests within my page (i guess i would have to send always all parameters).

I'm using JSF 2.0 with CDI. Any answer will be appreciated. Sadly i cannot provide any code example .. so i hope i was able to express my self clear enough.

greetings kukudas

You could create a new CDI scope or recreate the ViewScope in CDI. Take a look at CODI conversations as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM