• Now all data be ready for publish, We had made our blog alive now. Haha.



  • These days CCP GFW blocked all the IPs from US and when I switch my IP in google Cloud, the disk data cannot be restore again. I have to restart my blog totally, Now the website is still building…



Spring JSF integration: how to inject a Spring component/service in JSF managed bean?- Stack Overflow

Java PingBook 1 months ago (10-23) 14 0

Question

I understand that a managed bean works like a controller, because your only task is “link” the View Layer with Model.

To use a bean as a managed bean I must declare @ManagedBeanannotation, doing that I can communicate JSF with bean directly.

If I want to inject some component (from Spring) in this managedBean I have two possibles ways:

Choose the property in ManagedBean (like “BasicDAO dao”) and declare @ManagedProperty(#{“basicDAO”}) above the property. Doing it, i’m injecting the bean “basicDAO” from Spring in ManagedBean.
Declared @Controller in ManagedBean Class, then i’ll have @ManagedBean and @Controller annotations, all together. And in property “BasicDAO dao” i must use @Autowired from Spring.

Is my understanding correct?

Answer

There is another way to use Spring-managed beans in JSF-managed beans by simply extending your JSF bean from SpringBeanAutowiringSupport and Spring will handle the dependency injection.

@ManagedBean // JSF-managed.
@ViewScoped // JSF-managed scope.
public class GoodBean extends SpringBeanAutowiringSupport {

@Autowired
private SpringBeanClass springBeanName; // No setter required.

// springBeanName is now available.
}




Copyright from PingBook Blog, If not specified, they are original. This site uses BY-NC-SAProtocol authenticated.
For reprinting, please indicate the link of the original text:Spring JSF integration: how to inject a Spring component/service in JSF managed bean?- Stack Overflow
LIKE (0)
[1725641479@qq.com]
SHARE (0)
PingBook
Author:
We create, We sharing! Tag every value data your sharing
Submit comments
Cancel comments
emoji picture bold strikethrough center italic check in

Hi,you need to provide your name and email adress!

  • Name (Required)
  • Email (Required)
  • Website