Search code examples
springjsficefaces

Initialize JSF (ICEfaces) backing-bean only when page loads


I don't know how initialize a backing bean only when page loads, I am using Spring and ICEfaces.

For declare backing bean for ICEfaces I use the Spring annotation @Controller and el-resolver in faces.config.xml because I need inject service objects in the backing bean, and @ManagedBean doesn't work.

I use @PostConstructor but it is called when backing beans are created when application starts. I want to initialize my backing bean when page loads, not when backing bean is created.

doesn't work for me because it is called everytime a partial submit is doing and i need to initialize only one time

Thanks in advance and sorry for my english


Solution

  • I suspect @Controller has a default scope of "singleton" and as such is initialized during application startup. You should apply @Scope("session") if you want to have bean initialized when it's referred to for the first time and stay in the session. @PostConstruct will be also called once at the appropriate time.