View Javadoc

1   /*
2    * Copyright (c) 2007, Your Corporation. All Rights Reserved.
3    */
4   
5   /*
6    * Licensed to the Apache Software Foundation (ASF) under one
7    * or more contributor license agreements.  See the NOTICE file
8    * distributed with this work for additional information
9    * regarding copyright ownership.  The ASF licenses this file
10   * to you under the Apache License, Version 2.0 (the
11   * "License"); you may not use this file except in compliance
12   * with the License.  You may obtain a copy of the License at
13   *
14   *   http://www.apache.org/licenses/LICENSE-2.0
15   *
16   * Unless required by applicable law or agreed to in writing,
17   * software distributed under the License is distributed on an
18   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19   * KIND, either express or implied.  See the License for the
20   * specific language governing permissions and limitations
21   * under the License.
22   */
23  package org.apache.myfaces.orchestra.urlParamNav;
24  
25  import javax.faces.FacesException;
26  import javax.faces.application.ViewHandler;
27  import javax.faces.component.UIViewRoot;
28  import javax.faces.context.FacesContext;
29  import java.io.IOException;
30  import java.util.Locale;
31  
32  /***
33   * This view handler helps to preserve any url parameter you configured in your navigation.
34   *
35   * @see org.apache.myfaces.orchestra.urlParamNav.UrlParameterNavigationHandler
36   */
37  public class UrlParameterViewHandler extends ViewHandler
38  {
39  	private final ViewHandler original;
40  
41  	public UrlParameterViewHandler(final ViewHandler original)
42  	{
43  		this.original = original;
44  	}
45  
46  	public Locale calculateLocale(FacesContext context)
47  	{
48  		return original.calculateLocale(context);
49  	}
50  
51  	public String calculateRenderKitId(FacesContext context)
52  	{
53  		return original.calculateRenderKitId(context);
54  	}
55  
56  	public UIViewRoot createView(FacesContext context, String viewId)
57  	{
58  		return original.createView(context, viewId);
59  	}
60  
61  	public String getActionURL(FacesContext context, String viewId)
62  	{
63  		if (viewId != null)
64  		{
65  			int pos = viewId.indexOf('?');
66  			if (pos > -1)
67  			{
68  				String realViewId = viewId.substring(0, pos);
69  				String params = viewId.substring(pos);
70  
71  				return original.getActionURL(context, realViewId) + params;
72  			}
73  		}
74  		return original.getActionURL(context, viewId);
75  	}
76  
77  	public String getResourceURL(FacesContext context, String path)
78  	{
79  		return original.getResourceURL(context, path);
80  	}
81  
82  	public void renderView(FacesContext context, UIViewRoot viewToRender)
83  		throws IOException, FacesException
84  	{
85  		original.renderView(context, viewToRender);
86  	}
87  
88  	public UIViewRoot restoreView(FacesContext context, String viewId)
89  	{
90  		return original.restoreView(context, viewId);
91  	}
92  
93  	public void writeState(FacesContext context)
94  		throws IOException
95  	{
96  		original.writeState(context);
97  	}
98  }