1 16 17 package org.apache.struts.faces.application; 18 19 20 import java.io.IOException ; 21 import java.util.Locale ; 22 import javax.faces.FacesException; 23 import javax.faces.application.ViewHandler; 24 import javax.faces.component.UIViewRoot; 25 import javax.faces.context.ExternalContext; 26 import javax.faces.context.FacesContext; 27 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 import org.apache.struts.Globals; 31 32 33 40 41 public class ViewHandlerImpl extends ViewHandler { 42 43 44 46 47 53 public ViewHandlerImpl(ViewHandler handler) { 54 if (log.isDebugEnabled()) { 55 log.debug("Creating ViewHandler instance, wrapping handler " + 56 handler); 57 } 58 this.handler = handler; 59 } 60 61 62 64 65 68 private ViewHandler handler = null; 69 70 71 73 74 77 private static final Log log = 78 LogFactory.getLog(ViewHandlerImpl.class); 79 80 81 82 84 85 88 public ViewHandler getHandler() { 89 return this.handler; 90 } 91 92 93 98 public void setHandler(ViewHandler handler) { 99 this.handler = handler; 100 } 101 102 103 105 106 113 public void renderView(FacesContext context, UIViewRoot view) 114 throws IOException , FacesException { 115 116 if (log.isDebugEnabled()) { 117 log.debug("renderView(" + view.getViewId() + ")"); 118 } 119 ExternalContext econtext = context.getExternalContext(); 120 if (econtext.getSession(false) != null) { 121 Locale locale = (Locale ) 122 econtext.getSessionMap().get(Globals.LOCALE_KEY); 123 if (locale != null) { 124 if (log.isTraceEnabled()) { 125 log.trace("Setting view locale to " + locale); 126 } 127 view.setLocale(locale); 128 } 129 } 130 handler.renderView(context, view); 131 132 } 133 134 135 137 138 140 141 public Locale calculateLocale(FacesContext context) { 142 return handler.calculateLocale(context); 143 } 144 145 146 public String calculateRenderKitId(FacesContext context) { 147 return handler.calculateRenderKitId(context); 148 } 149 150 151 public UIViewRoot createView(FacesContext context, String viewId) { 152 return handler.createView(context, viewId); 153 } 154 155 156 public String getActionURL(FacesContext context, String viewId) { 157 return handler.getActionURL(context, viewId); 158 } 159 160 161 public String getResourceURL(FacesContext context, String viewId) { 162 return handler.getResourceURL(context, viewId); 163 } 164 165 166 public UIViewRoot restoreView(FacesContext context, String viewId) { 167 return handler.restoreView(context, viewId); 168 } 169 170 171 public void writeState(FacesContext context) throws IOException { 172 handler.writeState(context); 173 } 174 175 176 } 177 | Popular Tags |