Search code examples
jsf-2richfaces

Execute a bean action on page load using JSF2 and richFaces4


Im working on a JSF2 and richFaces4 application and I want to execute a backing bean action on load of one of my xhtml view.

Thanks.


Solution

  • If you make a bean @ViewScoped, a method with a @PostConstruct annotation will be invoked exactly once when rendering an xhtml view that references it.

    For example:

    @ManagedBean
    @ViewScoped
    public class Foo {
      @PostConstruct
      public void onPageLoad() {
      ...
      }
    }
    
    
    <h:outputText value=#{foo.property}"/>