1
votes

I am using JSF+Spring project my spring maanged bean is ViewScoped

my saving state is client.

<context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>

Following is my bean i found that constructor of bean and postconstruct method got call only on tomcat startup when it is spring managed bean instead if it is JSF managed bean constructor and postconstruct got call on every page refresh. Is it the real behavior if i want to call method on page refresh every time under spring managed bean what should id do ?

@Component
@ViewScoped
public class DataTableBean implements Serializable{

public DataTableBean() {
        super();
}

@PostConstruct
    private void loadDataData(){
        System.out.println("Post constructing");
    }
}
1
Just wondering , what exactly is the reason you're still using Spring? Its DI and service benefits has almost disappeared since the new CDI API in Java EE 6 and the new EJB API in Java EE 5.BalusC

1 Answers

3
votes

The @Component is a Spring specific annotation to manage beans by Spring. The @ViewScoped is a JSF specific annotation to specify the scope of a JSF managed bean @ManagedBean. JSF specific scope annotations does not work on a Spring managed bean at all. You should use the Spring specific @Scope annotation instead.

So, either just manage the bean by JSF:

@ManagedBean
@ViewScoped

Or homegrow a Spring "view" scope (this is namely not one of the default scopes available in Spring):

@Component
@Scope("view")