4

I have managed bean, and want to divide logic inside one of its methods according to which page called it, does some way exist to achieve this?

informatik01
  • 16,038
  • 10
  • 74
  • 104
Lostboy
  • 458
  • 3
  • 16
  • 1
    I strongly advise against this approach, as you increasing obscurity by confounding view and control. If you must, though, you can navigate the UIView by calling `FacesContext.getCurrentInstance().getExternalContext().getContextName()` – Bob Dalgleish Dec 13 '13 at 19:24

2 Answers2

9

This is available by UIViewRoot#getViewId().

String viewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();

I must however say that this is somewhat a smell. Depending on the concrete functional requirement for which you thought that examining the calling XHTML page would be the right solution, there may be better ways to achieve the concrete functional requirement.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
1

I think in two approachs the first is to get the referer header from the Http request it may have the url from the requesting page

FacesContext.getCurrentInstance().getExternalContext().getRequestHeaderMap().get("referer")

Other option is to navigate sending parameters, for example adding the viewId as parameter in the query string, in jsf-2 you can send parameters when the page navigate using the

I hope this will help you

Cesar Loachamin
  • 2,740
  • 4
  • 25
  • 33
  • Given the fact that JSF is by default postback based, examining the referrer is totally clumsy and unreliable (clients can control this value). Just examine the current view ID. – BalusC Dec 13 '13 at 19:37