facebook

JSF Backing Beans

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #266156 Reply

    smutchler
    Member

    After reading a number of articles on JSF, I feel I have a pretty good understanding of how JSF works. However, I cant seem to grasp how to share data between forms/views/jsp. I know I can create a backing bean and use session scope. However, what if one backing bean needs the data that is in another backing bean? Is it possible to reference beans from beans?

    Also, how do I keep from tightly coupling beans to views. For example, what if a view (that edits data) can be accessed from multiple contexts. Do they all have to share the same backing bean?

    Thanks,

    Scott

    #266300 Reply

    Riyad Kalla
    Member

    Scott,
    To address the bean-to-bean issue, you use the faces-config.xml file to bind beans together. like UserBean will use DAOBean let’s say. If you have a “dao” property on your UserBean, in your faces-config file, you would set the “dao” property, using an expression of something like #{daoBean} in the XML itself, and this value is read, interpreted, and injected at run time with the instantiated DAOBean (my notation might be off, just look into setting values for beans in the config file, there is away to set dynamic values). Or a lot of people will just say “that’s what Spring is for”, either way works fine.

    As far as Views tied to Beans, I don’t quite understand the question. Any JSF page you write will likely have expressions in it that pulls values from it’s beans. So there is no way to avoid this relationship… like inside of your Profile.jsp page, you may have code like:

    
    Welcome #{SessionBean.firstName}, you last logged in on #{SessionBean.lastLogin}. There are #{ApplicationBean.userCount} other users on the system right now.
    

    So I’m not sure what your questions is actually concerning, but if you mean here like “how do I not couple the Profile.jsp page and the beans above”, then I have no idea. You have to.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: JSF Backing Beans

You must be logged in to post in the forum log in