2012-04-29 70 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;