1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.portals.bridges.jsf;
17
18 import javax.faces.component.NamingContainer;
19 import javax.faces.component.UIViewRoot;
20 import javax.faces.context.FacesContext;
21
22 /***
23 * A portlet view root that implements a naming container to creates unique
24 * client ids.
25 * @author Matthew Bruzek
26 */
27 public class PortletUIViewRoot extends UIViewRoot implements NamingContainer
28 {
29 /*** A portlet view id constant to prepend to the namespace. */
30 public static final String VIEW_PREFIX = "view";
31
32 /*** The default constructor calls the UIViewRoot default constructor. */
33 public PortletUIViewRoot()
34 {
35 super();
36 }
37
38 /***
39 * The convenience constructor creates a PortletUIViewRoot from a UIViewRoot.
40 * @param viewRoot The UIViewRoot to use when creating this object.
41 */
42 public PortletUIViewRoot( UIViewRoot viewRoot )
43 {
44 setLocale( viewRoot.getLocale() );
45 setRenderKitId( viewRoot.getRenderKitId() );
46 setViewId( viewRoot.getViewId() );
47 }
48
49 /***
50 * Return a string which can be used as output to the response which uniquely
51 * identifies a component within the current view.
52 * @param context The FacesContext object for the current request.
53 */
54 public String getClientId( FacesContext context )
55 {
56 if ( context == null )
57 throw new NullPointerException( "context can not be null." );
58
59 String nameSpace = context.getExternalContext().encodeNamespace( "" );
60 return VIEW_PREFIX + nameSpace;
61 }
62 }