简体   繁体   中英

How can I pass an object from another object held within one JSF Bean to an other Bean in same view?

I have a JPA entity Person as person can have many contacts (these are organisations not persons).

On the JSF page I need to display the person and all the contacts. This is what I thought about approaching this.

  • Create Two facelet pages one for person and one for contacts (that belong to person)
  • Create Two Viewscoped backing beans one for person page one for contacts page
  • Using UI include group the two into single page for end user.

Problem is that I do not know how can I pass the List<Contact> (lazy loaded but probably not relevant in context of this question but still mentioning any way) from Person entity which is inside the PersonBackingBean has to the ContactsBackingBean gracefully .

May be my approach is wrong and there should be only one Bean .

I'd create a Controller Bean and prepare the data in it. The data preperation can take place when you process an action when selecting the person to show.

Add two get methods to that controller with one getting the persons and the second one getting the contacts.

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