1 23 package com.sun.enterprise.tools.jsfext.layout; 24 25 import com.sun.enterprise.tools.jsfext.component.ComponentUtil; 26 import com.sun.enterprise.tools.jsfext.layout.descriptor.LayoutComponent; 27 import com.sun.enterprise.tools.jsfext.layout.descriptor.LayoutDefinition; 28 import com.sun.enterprise.tools.jsfext.layout.descriptor.LayoutElement; 29 import com.sun.enterprise.tools.jsfext.layout.LayoutDefinitionManager; 30 import com.sun.enterprise.tools.jsfext.util.LogUtil; 31 32 import javax.faces.component.UIComponent; 33 import javax.faces.component.UIViewRoot; 34 import javax.faces.context.ExternalContext; 35 import javax.faces.context.FacesContext; 36 37 38 50 public class LayoutViewRoot extends UIViewRoot { 51 52 55 public LayoutViewRoot() { 56 super(); 57 } 58 59 75 public void processDecodes(FacesContext context) { 76 77 ExternalContext extCtx = context.getExternalContext(); 79 String targetId = extCtx.getRequestParameterMap().get(LayoutViewHandler.LAVA_CHANNEL_KEY); 80 if ((targetId != null) && !targetId.equals("")) { 81 85 UIComponent target = findComponent(":"+targetId); 87 if (target == null) { 88 LayoutDefinition def = getLayoutDefinition(context); 91 if (def != null) { 92 def.decode(context, this); 93 } 94 super.processDecodes(context); 95 return; 96 } 97 extCtx.getRequestMap().put(LayoutViewHandler.LAVA_CHANNEL_TARGET_KEY, target); 98 99 target.processDecodes(context); 101 processApplication(context); 102 103 context.renderResponse(); 105 } else { 106 108 LayoutDefinition def = getLayoutDefinition(context); 109 if (def != null) { 110 def.decode(context, this); 111 } 112 super.processDecodes(context); 113 } 114 } 115 116 125 public UIComponent getChild(FacesContext context, String id) { 126 if ((id == null) || (id.trim().equals(""))) { 127 return null; 129 } 130 131 UIComponent childComponent = ComponentUtil.findChild(this, id, id); 133 if (childComponent != null) { 134 return childComponent; 135 } 136 137 LayoutDefinition ld = getLayoutDefinition(context); 140 if (ld == null) { 141 return null; 143 } 144 145 LayoutElement elt = 147 LayoutDefinition.getChildLayoutElementById(context, id, ld, this); 148 149 return getChild(context, (LayoutComponent) elt); 151 } 152 153 167 public UIComponent getChild(FacesContext context, LayoutComponent descriptor) { 168 UIComponent childComponent = null; 169 170 if (descriptor == null) { 172 throw new IllegalArgumentException ("The LayoutComponent is null!"); 173 } 174 175 String id = descriptor.getId(context, this); 177 if ((id != null) && !(id.trim().equals(""))) { 178 childComponent = ComponentUtil.findChild(this, id, id); 180 if (childComponent != null) { 181 return childComponent; 182 } 183 } 184 185 188 descriptor.beforeCreate(context, this); 190 191 childComponent = 193 ComponentUtil.createChildComponent(context, descriptor, this); 194 195 descriptor.afterCreate(context, childComponent); 197 198 return childComponent; 200 } 201 202 212 public LayoutDefinition getLayoutDefinition(FacesContext context) { 213 if (_layoutDefinition != null) { 215 return _layoutDefinition; 216 } 217 218 String key = getLayoutDefinitionKey(); 220 if (key == null) { 221 return null; 222 } 223 224 LayoutDefinitionManager ldm = 226 LayoutDefinitionManager.getManager(context); 227 228 try { 230 _layoutDefinition = ldm.getLayoutDefinition(key); 231 } catch (java.io.IOException ex) { 232 if (LogUtil.configEnabled(this)) { 233 LogUtil.config( 234 "Unable to get LayoutDefinition for '" + key + "'."); 235 } 236 } 237 238 return _layoutDefinition; 240 } 241 242 247 public String getLayoutDefinitionKey() { 248 return _ldmKey; 249 } 250 251 256 public void setLayoutDefinitionKey(String key) { 257 _ldmKey = key; 258 } 259 260 269 public Object saveState(FacesContext context) { 270 Object [] values = new Object [2]; 271 values[0] = super.saveState(context); 272 values[1] = _ldmKey; 273 return values; 274 } 275 276 283 public void restoreState(FacesContext context, Object state) { 284 Object [] values = (Object []) state; 285 super.restoreState(context, values[0]); 286 _ldmKey = (java.lang.String ) values[1]; 287 } 288 289 290 private String _ldmKey = null; 291 private transient LayoutDefinition _layoutDefinition = null; 292 } 293 | Popular Tags |