Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to edit two entities, of the same type, at the same time ? e.g. Two backing beans  RSS feed

 
Gareth Force
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should be a basic question, but being relatively new to JSF, I cant work out how this use case is supported.

I have a tabbed application, a tab with a list of entities ( tab 1 ), and when an entity is selected, it opens in a new tab to be edited ( tab 2 ), with the associated backing bean ( This works fine ). However I also want to be able to open another entity ( tab 3 ), this is the same type, e.g. same backing bean. This causes all sorts of 'fun' where by tab 2 now displays the content of the bean from tab 3, as its the same backing bean. ( and a heap of ID issues ).

How can I generate two beans of the same type ? I guess its down to scopes ?

Any ideas / suggestions ?

Thanks in advance,

G
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the same class and have multiple instances. However, each instance has to have a distinct name. You can do that by defining the bean (and its name) in the faces-config.xml file. You can't use the annotation mechanism instead since only one name can be mapped to a bean via annotation.

I think more likely what you need is a common backing bean that has a collection of "tab beans" where the tab beans are non-JSF POJOs. If we call the backing bean "containerBean" and the collection is contained in a Map object that's a property of that bean, you can reference the individual "tab beans" by name.



Or, if you prefer to use a List as the tab bean container:




Admittedly this is a relatively cumbersome notation, but it should do the job.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!