Springで管理されているJSFBeanを使用していますが、SpringまたはJSFのアノテーションタグEx。@ scopeを使用する必要がありますか?
JSFアノテーションである@ViewScopedが機能せず、リクエストスコープとして動作していることに気づきましたか?
Springで管理されているJSFBeanを使用していますが、SpringまたはJSFのアノテーションタグEx。@ scopeを使用する必要がありますか?
JSFアノテーションである@ViewScopedが機能せず、リクエストスコープとして動作していることに気づきましたか?
Spring + JSF統合に使用している場合はorg.springframework.web.jsf.el.SpringBeanFacesELResolver
、スコープにorg.springframework.context.annotation.Scope
注釈を付ける必要があります。
SpringにはViewスコープはありませんが、そのようなスコープをカスタム実装できます。これまたはこれを参照してください。
この記事を読む:この記事の情報: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);
}
...
}
次に、バッキングBeanにそのスーパークラスを拡張させると、Spring Beanを自動配線して、JSF固有のビュースコープを利用できるようになります。
@ManagedBean
@ViewScoped
public class MyBackingBean extends AutowireableManagedBean {
@Autowired
private MyDao myDao;