Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
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
 
Saloon Keeper
Posts: 22495
151
Android Eclipse IDE Tomcat Server Redhat Java 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.
    Bookmark Topic Watch Topic
  • New Topic