开发者

JSF 2 : How do you partition your JSF Beans?

I've had a confusing time determining how to partition my JSF Beans.

What i have in mind currently :

  1. Have a single JSF Bean (ViewScope - to support multitab in the b开发者_运维问答rowser) for every single JSF xhtml page
  2. I can share parameters using the view params or the flash scope scope
  3. Have a session bean that shares a context object that contains the user information, etc that can be shared for all view-scoped-JSF-beans

Do you have any suggestions on how to decide / design the JSF Beans ?

Thank you !


Update

Sorry for not being clear on partitioning thing :

What i had in mind in partitioning the JSF Beans is about, what will be the factor for creating a JSF Bean. Or in another word, how should i divide the beans based on the functions ? or in another word, what is the best practice desigining the JSF Beans ?

And my original post was to ask for opinion whether it's ok to design like what i currently have in mind.

Is it ok to have one view-scoped-bean to handle each page, or is it bad because the beans got too many as the amount of pages increase, or perhaps something else ?

And as an additional note, this post actually sparks from one of the comments in my other post

I'll also suggest to review your architecture. Are you sure you need all thoses beans, partitionned exactly like this? This sounds like something which will be difficult to maintain.


Actually you should do what fits your situation best. Many pages may use a single bean but it is not a one size fits all situation.

For instance a webshop may display articles and information from the customers basket in a single page where the basket data is coming from a basketbean and the articles from a catalogbean. So it would be using two beans for one page.

Another example would be a mulipage order form where you handle all pages with a single bean because they are related to each other.


  1. Have a ViewScoped backing bean for each page.( They are made for that purpose and they are definitely not as much costly as SessionScoped Beans)
  2. Keep a session bean to maintain the user data, for each session.
  3. Avoid Using ApplicationScoped beans when its not necessary because it is unlikely to be garbage collected frequently.

This is what I consider baselines before creating a JSF ManagedBean.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜