0

I am trying to invoke a bean action on page load, bean is registered in session scope.

I have accomplish this with js like this:- document.getElementById('form1:show_data').click();

I know it can be done alternatively by calling the action in bean constructor, but in session scope the action is called only once. is there any other of doing this in JSF 1.

Zeeshan Bin Iqbal
  • 1,206
  • 2
  • 8
  • 8
  • Possible duplicate of [Invoke JSF managed bean action on page load](https://stackoverflow.com/questions/2451154/invoke-jsf-managed-bean-action-on-page-load) – Jasper de Vries Dec 07 '17 at 14:07

1 Answers1

1

You can still create another bean in the request scope and in its constructor get the session bean and call whatever you need to call.

public RequestScopedBean() {
    FacesContext fc = FacesContext.getCurrentInstance();

    SessionScopedBean ssb = (SesssionScopedBean) fc
        .getApplication()
        .getVariableResolver()
        .resolveVariable(fc, "sessionScopedBean");
    ssb.callSomething();
}

You still have to reference the request scoped bean in the view somehow just to ensure it will be created.

This will do:

<f:subview rendered="#{requestScopedBean = null}" />