Sunday, June 29, 2014

CustomViewHandler in Webcenter Portal

This post is about understanding and overriding the CustomViewHandler defined in Webcenter Portal.
CustomViewHandler extends the default ViewHandler provided by JSF implementation.

"ViewHandler is the pluggablity mechanism for allowing implementations of or applications using the JavaServer Faces specification to provide their own handling of the activities in the Render Response and Restore View phases of the request processing lifecycle. This allows for implementations to support different response generation technologies, as well as alternative strategies for saving and restoring the state of each view. "
See Java Doc for more details.

Webcenter Portal CustomViewHandler(oracle.webcenter.portalframework.sitestructure.handler) extends JSF ViewHandlerWrapper. It is defined in public_html\WEB-INF\faces-config.xml file.






 I created a class MyCustomViewHandler (extends CustomViewHandler) and registered it in faces-config.xml. I tried to debug the behaviour of CustomViewHandler while navigating between the view activities. Here are my findings -

1. Scenario
Navigating to the navigation resource of type Page and Redirect to URL option checked.
Request for the page comes in the form of prettyURL.




When a request for the page comes in the form of a pretty URL(For Ex: http:<WebServer Host Name>/<context root>/faces/contact/support), the createView(FacesContext ctx, String url) and restoreView(FacesContext ctx, String url) intercept the request.

CreateView method internally calls getPageTargetViewId() to lookup the internal viewId for the given PrettyURL and create and return a new UIViewRoot instance initialized with information from the argument FacesContext and viewId.

Flow of the methods called internally - 


If the redirect option is checked browser will show the internal viewId URL.

2. Scenario
Navigating to the navigation resource of type Page and Redirect URL in Page Template option checked. Request for the page comes in the form of prettyURL.




Redirect to URL option is not checked, so createView method will be called only once with the URL parameter equal to the requested prettyURL. Pretty URL is internally looked upon and createView method returns a new UIViewRoot for the internal viewId. Difference is in this case browser will show the prettyURL instead of internal viewId URL.

createView method can be modified in the overridden MyCustomViewHandler class to map the customized pretty URL to the internal view Id. I will discuss this topic in my next post.

                    

No comments:

Post a Comment