When should you explain the name of the managed bean?

With all the research that I did to create managed beans, I did not notice (or perhaps did not miss) when to use an explicit bean name for example. @Named(name = "someBean").

I suppose it's hard for me to understand why you want to name a bean nothing but the name of your class:

@Named(name = "someBean")
public class SomeBean implements Serializebale {
}

With all the examples I've seen, some use an explicit name, and some just use @Namedto leave the class name default. None of these examples was explained by why they used explicit naming. It seems more confusing to try and access a bean with anything other than a class name.

So, I ask the question: is there any rule or convention about when you want to provide an access name different from your class name, or do people just do it if they have a long class name that they want to access with less typing?

+4
source share
1 answer

Your question deals with the design paradigm Configuration by configuration . In order to deal with errors of the past, which, in particular, is associated with the need for advanced configuration, many default parameters have been introduced since the last releases of many Java frameworks / APIs, etc. JSF / CDI is no exception in this case.

, bean @ManagedBean, @RequestScoped, EL simpleClassName:

name() - bean -name. name , bean . , ManagedBean com.example.Bean , bean bean. , , bean.

bean NoScoped, RequestScoped, ViewScoped, SessionScoped, ApplicationScoped CustomScoped. , bean , RequestScoped.

CDI beans, EJB, JPA Entity .. , , , @ManagedBean(name = "myBean") public class MyBean bean .

, bean , , , : @ManagedBean(name = "settings") public class UserDefinedSettingsBean.

+5

All Articles