1

I have two different JSF2 pages with a shared backing bean. How can I pass a parameter from page to the backing bean (on page load - method with @PostConstruct) so that it knows which page is currently being used.

I know it's possible to use an <f:event> like preRenderView (like this), but it then requires a method as well as a field in the backing bean. Is this possible with something like f:attribute or f:param, without any extra method in the backing bean?

Community
  • 1
  • 1
Mohsen
  • 3,512
  • 3
  • 38
  • 66
  • Seel this link for passing parameter using @PostConstruct http://stackoverflow.com/questions/4673844/how-can-i-send-a-parameter-to-be-used-in-the-postconstruct-method-of-a-backing – Bhushan Kawadkar Oct 30 '12 at 18:34

1 Answers1

1

If the bean is request scoped, just get the view ID as managed property by #{view.viewId}.

@ManagedProperty("#{view.viewId}")
private String viewId; // +setter

If the bean is view scoped, just get the view ID directly by UIViewRoot#viewId().

private String viewId;

@PostConstruct
public void init() {
    viewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();
    // ...
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555