You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sv...@apache.org on 2005/09/30 03:28:15 UTC

svn commit: r292596 - /myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamicRenderer.java

Author: svieujot
Date: Thu Sep 29 18:28:12 2005
New Revision: 292596

URL: http://svn.apache.org/viewcvs?rev=292596&view=rev
Log:
GraphicImageDynamic : First attempt to use compact tree.

Modified:
    myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamicRenderer.java

Modified: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamicRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamicRenderer.java?rev=292596&r1=292595&r2=292596&view=diff
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamicRenderer.java (original)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/graphicimagedynamic/GraphicImageDynamicRenderer.java Thu Sep 29 18:28:12 2005
@@ -18,15 +18,23 @@
 
 import java.io.IOException;
 
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.StateManager;
 import javax.faces.application.ViewHandler;
 import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
+import javax.faces.context.FacesContextFactory;
 import javax.faces.context.ResponseWriter;
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.lifecycle.LifecycleFactory;
 
 import org.apache.myfaces.renderkit.RendererUtils;
 import org.apache.myfaces.renderkit.html.HTML;
 import org.apache.myfaces.renderkit.html.HtmlRendererUtils;
 import org.apache.myfaces.renderkit.html.ext.HtmlImageRenderer;
+import org.apache.myfaces.util.StateUtils;
 
 /**
  * @author Sylvain Vieujot
@@ -59,11 +67,46 @@
         out.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
         out.writeText("document.getElementById('"+clientId+"').src='",null);
         out.writeText(context.getExternalContext().encodeActionURL(actionURL+"?affectedGraphicImageComponent="+clientId),null);
-        if( graphicImageDynamic.getInitializationParameters() != null )
-        	out.write('&'+graphicImageDynamic.getInitializationParameters()+"';");
-        else
-        	out.writeText("&jsf_tree_64='+encodeURIComponent(document.getElementById('jsf_tree_64').value)+'&jsf_state_64='+encodeURIComponent(document.getElementById('jsf_state_64').value)+'&jsf_viewid='+encodeURIComponent(document.getElementById('jsf_viewid').value);", null);
+        
+        // Set compact to True to test serializing a compact tree (fails as of now).
+        boolean compact = false;
+        
+        if( compact ){
+        	StateManager stateManager = context.getApplication().getStateManager();
+        	FacesContext compactContext = buildCompactView(context, graphicImageDynamic);
+        	StateManager.SerializedView serializedView = stateManager.saveSerializedView(compactContext);
+        	String jsf_tree_64 = StateUtils.encode64( serializedView.getStructure() );
+        	String jsf_state_64 = StateUtils.encode64( serializedView.getState() );
+        	out.writeText("&jsf_tree_64='+encodeURIComponent('"+jsf_tree_64+"')+'&jsf_state_64='+encodeURIComponent('"+jsf_state_64+"')+'&jsf_viewid='+encodeURIComponent(document.getElementById('jsf_viewid').value);", null);
+        }else{
+	        if( graphicImageDynamic.getInitializationParameters() != null )
+	        	out.write('&'+graphicImageDynamic.getInitializationParameters()+"';");
+	        else
+	        	out.writeText("&jsf_tree_64='+encodeURIComponent(document.getElementById('jsf_tree_64').value)+'&jsf_state_64='+encodeURIComponent(document.getElementById('jsf_state_64').value)+'&jsf_viewid='+encodeURIComponent(document.getElementById('jsf_viewid').value);", null);
+        }
         out.endElement(HTML.SCRIPT_ELEM);
+    }
+    
+    private FacesContext buildCompactView(FacesContext realContext, GraphicImageDynamic graphicImageDynamic){
+    	FacesContextFactory facesContextFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+    	LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+    	Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
+    	FacesContext facesContext = facesContextFactory.getFacesContext(
+    									realContext.getExternalContext().getContext(),
+    									realContext.getExternalContext().getRequest(),
+    									realContext.getExternalContext().getResponse(),
+    									lifecycle);
+    	Application application = facesContext.getApplication();
+        ViewHandler viewHandler = application.getViewHandler();
+        String viewId = realContext.getViewRoot().getViewId();
+        UIViewRoot viewRoot = viewHandler.createView(facesContext, viewId);
+        viewRoot.setViewId(viewId);
+        
+        //viewRoot.getChildren().add( graphicImageDynamic );
+        
+        facesContext.setViewRoot(viewRoot);
+        
+        return facesContext;
     }
 
     public void decode(FacesContext facesContext, UIComponent component)