开发者

Reuse of multiple CDI @Named bean instances of the same class in a JSF page

开发者 https://www.devze.com 2023-02-01 06:56 出处:网络
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 JS

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开发者_Python百科. 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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消