2012-04-29 91 views
1

我正在使用Spring管理的JSF bean,现在我必须使用注释标记Ex。@ scope of spring还是JSF?Spring管理的JSF bean

我注意到@ViewScoped是JSF注释不起作用,仍然表现为请求范围?

回答

1

如果使用org.springframework.web.jsf.el.SpringBeanFacesELResolver为Spring + JSF集成,那么你需要用org.springframework.context.annotation.Scope注释标记范围。在这篇文章中信息:

0

有春天没有查看范围,但是我们可以自定义实现这样scope.Refer thisthis

0

阅读这篇文章http://www.beyondjava.net/blog/integrate-jsf-2-spring-3-nicely/

我这样做:

定义JSF支持bean这样一个抽象超:

public abstract class AutowireableManagedBean { 

    protected Logger logger = LoggerFactory.getLogger(getClass()); 

    protected AutowireCapableBeanFactory ctx; 

    @PostConstruct 
    protected void init() { 
     logger.debug("init"); 
     ctx = WebApplicationContextUtils 
       .getWebApplicationContext(
         (ServletContext) FacesContext.getCurrentInstance() 
           .getExternalContext().getContext()) 
       .getAutowireCapableBeanFactory(); 
     // The following line does the magic 
     ctx.autowireBean(this); 
    } 
    ... 
} 

然后,让你的后盾豆扩展该超类,你将能够自动连接Spring bean并利用特定于JSF的视图范围:

@ManagedBean 
@ViewScoped 
public class MyBackingBean extends AutowireableManagedBean { 

    @Autowired 
    private MyDao myDao;