2012-04-29 20 views
1

私はSpring管理のJSF beanを使用していますが、今は注釈タグを使用する必要がありますか?Springの範囲かJSFか?Spring管理のJSF bean

@ViewScopedはJSFアノテーションが機能しておらず、リクエストスコープとして動作していることに気付きましたか?

答えて

1

を実装することができ、その後、あなたはorg.springframework.context.annotation.Scope注釈と範囲をマークする必要があります。

0

あり春にはビュースコープはありませんが、あなたは春+ JSFとの統合のためのorg.springframework.web.jsf.el.SpringBeanFacesELResolverを使用している場合、我々は、カスタムなscope.Refer thisthis

0

この記事を読む:この記事の情報:http://www.beyondjava.net/blog/integrate-jsf-2-spring-3-nicely/

を私はこれをした:あなたのバッキング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); 
    } 
    ... 
} 

は、このようなJSFバッキングBeanの抽象スーパークラスを定義します。そのスーパークラスを拡張すると、Spring Beanをオートワイヤーすることができ、JSF固有のビュースコープを使用することができます:

@ManagedBean 
@ViewScoped 
public class MyBackingBean extends AutowireableManagedBean { 

    @Autowired 
    private MyDao myDao; 
関連する問題