Get context root or URL of ADF / Webcenter application

Hi,

I have requirement to get the context root in javascript on page load.Not on any event.If you need on java you can try my previous solution like get the current viewId or url in ADF using ControllerContext. Following solution will work in any application

Try this

window.location.protocol = “http:” // gives you protocol
window.location.host = “techartifact.com”
window.location.pathname = “blogs/2015/08/building-taskflow-for-reuse.html”

var pathArray = window.location.pathname.split(‘/’);
var secondLevelLocation = pathArray[1]; // this will give you the context root of application

Similarly you can get the current page number or param etc in javascript.

Similarly if you need this context root on some button event you can try like passing it using a af:clientAttribute and EL as *#{facesContext.externalContext.request.contextPath}*

<af:document id=”d1”>
<af:resource type="javascript">
        function onLoad(evt){
            var path=evt.getSource().getProperty("pagePath");
            window.location.replace(path);// here we were trying a redirect , just an example
        }
        </af:resource>
        <af:clientListener method="onLoad" type="load"/>
        <af:clientAttribute name="pagePath"
                            value="#{facesContext.externalContext.request.contextPath}/faces/<pagePath>"/>
….
</af:document>

 

Happy coding in techartifact

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