Question

I'd like to use multiple instances of the same CDI Named bean in a JSF2 page. (Imagine I have a backing bean to access a contentmanager category, but I want to show multiple categories in the same JSF page) I wonder how can I "override" the default name of @Named annotation so I can have those 3 o 4 instances in my page. (¿Remember the old JSP "useBean" tag to use a bean in a page... you could use multiple instances of the same class this way) I've search about beans.xml but don't find it. Can I use old faces-context.xml "managed bean" entry? Don't know if that will apply to a CDI @Named bean or can only be use for old non CDI managed beans.

thanks for any info, Ignacio

Was it helpful?

Solution

You can just make your bean @Dependent (or remove existing scope annotation), and as long as you don't use the bean twice in the same EL expression, you'll get new underlying instances.

OTHER TIPS

You can't have more than one bean instance in a given scope. So for example, in one request, you can't have two instances of a request-scoped bean. That's the point of the scopes.

So I guess you should not have your beans managed at all. Just put them as request attributes and access them via EL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top