get the current viewId or url in ADF using ControllerContext

ControllerContext – Context class for per request per web application Controller information. It have various method when you need to perform
action programmatically .It Provide per-request information about the controller state for a web application.

Use getInstance() method to get the context which includes:

1. ViewPortContext (current view rendered in a browser window, a modal dialog or a region).
2. Global ViewActivity URL (url of a view activity in an unbounded task flow).
3. Local view activity url.
4. Task flow url view activity view id.
5. Savepoint restore url.

getCurrentRootViewPort() -Returns a ViewPortContext corresponding to the current root view port. The root view port is the view port for the current browser window/tab.

getGlobalViewActivityURL(ViewId) – Generate a URL for a view activity in the unbounded task flow.
Note: the view activity being referenced must be in the unbounded task flow. URL access to view activities within bounded task flows is not supported. It is caller’s responsibility to ensure that the view activity exists.

Returns:
a properly encounded URL that will result in navigation to the specified view activity.

getSavePointRestoreURL(savePointId) -Generates a URL to a save point restore activity within the current web application.

getViewActivityViewID(localViewId) -Generate view ID for a view activity inside a task flow definition. The view ID can be used when creating a UIViewRoot representing this view activity so that it can be launched in a dialog window. It is caller’s responsibility to ensure that the view activity exists.

Get the current View Id

 
ControllerContext.getInstance().getCurrentViewPort().getViewId();

Get request URL of a view activity

 
String url = ControllerContext.getInstance().getGlobalViewActivityURL(viewId)

or 

String viewId = "/department"; 
String url = ControllerContext.getInstance().getGlobalViewActivityURL(viewId);

Navigate programmatically among view activities:

 
ControllerContext.getInstance().getCurrentViewPort().setViewId("Department");  //Ensure "Department" is a valid view id in current task flow