This is more of a general question, so that I a better understand about JSF and managed bean. So when people having multiple managed bean, is it solely because they want to group methods with the same scoped(RequestScoped, ApplicationScoped, SessionScope...) together? Or is there some other reason? What would happen if you inject managed bean with different scope into another? and why would they want to inject one bean with different scope to another, can I not just from JSF access different bean base on my need instead of inject one bean to another?
I'm fairly new to JSF, but I have to yet see a managed bean inside a managed bean. Personally I have several managed beans in my appliaction, because each one is supposed to be a controller for a different view (some are Session Scoped, most of them are Request scoped and one or two are Conversation scoped). Let's say I have a user registration form, then I create a UserRegistrationController which is a managed bean for that view, it has a POJO like lets say UserRegistration with all the properties that are used in the view, and some methods like "registerUser()" which then pushes it to a service which takes care of all the work.
So when people having multiple managed bean, is it solely because they want to group methods with the same scoped(RequestScoped, ApplicationScoped, SessionScope...) together? Or is there some other reason?
That depends on the data the bean holds and the responsibilities of the bean. If it holds request scoped data (e.g. form input values and form actions), then the bean should go in request scope. If it holds session scoped data (e.g. logged-in user, user-specific settings like locale, etc), then the bean should go in session scope. If it holds application scoped data (e.g. dropdown values and other application wide constants), then the bean should go in application scope. It makes logically sense.
What would happen if you inject managed bean with different scope into another?
You can only inject a bean of the same or a broader scope in another bean. E.g. request, session or application scoped bean can be injected in a request scoped bean. JSF just sets it as a property of the target bean. This has no side effects. JSF will already error when you attempt to inject a bean of a narrower scope in another bean. You cannot inject a request scoped bean in a session scoped one. It makes perfectly sense. There can be more than one request scoped bean inside the same session, which one should JSF pick?
and why would they want to inject one bean with different scope to another, can I not just from JSF access different bean base on my need instead of inject one bean to another?
It'll only add nasty boilerplate code. Why not just let JSF handle it transparently? There's no need to take over JSF's responsibilities in your own hands. Injecting is cheap, even if you don't need the injected bean in the particular use case, it won't harm.