[richfaces-svn-commits] JBoss Rich Faces SVN: r2556 - in trunk: framework/impl/src/main/java/org/ajax4jsf/resource and 4 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Tue Aug 28 20:17:07 EDT 2007


Author: alexsmirnov
Date: 2007-08-28 20:17:07 -0400 (Tue, 28 Aug 2007)
New Revision: 2556

Added:
   trunk/samples/seamEAR/ejbs/src/main/java/org/richfaces/seam/Media.java
   trunk/samples/seamEAR/ejbs/src/main/java/org/richfaces/seam/MediaBean.java
   trunk/samples/seamEAR/ejbs/src/main/java/org/richfaces/seam/MediaData.java
   trunk/samples/seamEAR/wars/seamWebapp/src/main/webapp/pages/mediaOutput.xhtml
Modified:
   trunk/framework/impl/src/main/java/org/ajax4jsf/event/AjaxPhaseListener.java
   trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceLifecycle.java
   trunk/samples/seamEAR/wars/seamWebapp/pom.xml
   trunk/samples/seamEAR/wars/seamWebapp/src/main/webapp/WEB-INF/web.xml
Log:
Fix http://jira.jboss.com/jira/browse/AJSF-54

Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/event/AjaxPhaseListener.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/event/AjaxPhaseListener.java	2007-08-28 23:44:27 UTC (rev 2555)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/event/AjaxPhaseListener.java	2007-08-29 00:17:07 UTC (rev 2556)
@@ -132,7 +132,8 @@
 			AjaxContext.getCurrentInstance(context).setViewIdHolder(null);
 
 			UIViewRoot root = context.getViewRoot();
-			log.debug(Messages.getMessage(
+if (null != root) {
+							log.debug(Messages.getMessage(
 					Messages.ENTER_BEFORE_RENDER_VIEW_PHASE, root.getViewId(),
 					root.getRenderKitId()));
 
@@ -149,8 +150,9 @@
 						renderKitId));
 				root.setRenderKitId(renderKitId);
 			}
-		} else if (phaseId == PhaseId.RESTORE_VIEW) {
 
+			}		} else if (phaseId == PhaseId.RESTORE_VIEW) {
+
 		}
 	}
 

Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceLifecycle.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceLifecycle.java	2007-08-28 23:44:27 UTC (rev 2555)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceLifecycle.java	2007-08-29 00:17:07 UTC (rev 2556)
@@ -22,24 +22,41 @@
 package org.ajax4jsf.resource;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 
 import javax.faces.FacesException;
+import javax.faces.FactoryFinder;
 import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
 import javax.faces.event.PhaseListener;
 import javax.faces.lifecycle.Lifecycle;
+import javax.faces.lifecycle.LifecycleFactory;
+import javax.servlet.ServletException;
 
 import org.ajax4jsf.resource.InternetResource;
 import org.ajax4jsf.resource.ResourceContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * Lifecycle for simulate faces request processing for resource.
+ * 
  * @author shura (latest modification by $Author: alexsmirnov $)
  * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:56:56 $
- *
+ * 
  */
 public class ResourceLifecycle extends Lifecycle {
 
-	/* (non-Javadoc)
+	private Lifecycle lifecycle;
+	
+	private static final Log _log = LogFactory.getLog(ResourceLifecycle.class);
+
+	/*
+	 * (non-Javadoc)
+	 * 
 	 * @see javax.faces.lifecycle.Lifecycle#addPhaseListener(javax.faces.event.PhaseListener)
 	 */
 	public void addPhaseListener(PhaseListener arg0) {
@@ -47,7 +64,9 @@
 
 	}
 
-	/* (non-Javadoc)
+	/*
+	 * (non-Javadoc)
+	 * 
 	 * @see javax.faces.lifecycle.Lifecycle#execute(javax.faces.context.FacesContext)
 	 */
 	public void execute(FacesContext arg0) throws FacesException {
@@ -55,7 +74,9 @@
 
 	}
 
-	/* (non-Javadoc)
+	/*
+	 * (non-Javadoc)
+	 * 
 	 * @see javax.faces.lifecycle.Lifecycle#getPhaseListeners()
 	 */
 	public PhaseListener[] getPhaseListeners() {
@@ -63,7 +84,9 @@
 		return null;
 	}
 
-	/* (non-Javadoc)
+	/*
+	 * (non-Javadoc)
+	 * 
 	 * @see javax.faces.lifecycle.Lifecycle#removePhaseListener(javax.faces.event.PhaseListener)
 	 */
 	public void removePhaseListener(PhaseListener arg0) {
@@ -71,22 +94,101 @@
 
 	}
 
-	/* (non-Javadoc)
+	/*
+	 * (non-Javadoc)
+	 * 
 	 * @see javax.faces.lifecycle.Lifecycle#render(javax.faces.context.FacesContext)
 	 */
 	public void render(FacesContext arg0) throws FacesException {
 		// TODO Auto-generated method stub
 
 	}
-	
+
 	/**
 	 * @param context
 	 * @param resource
-	 * @throws IOException 
+	 * @throws IOException
 	 */
-	public void send(ResourceContext resourceContext, InternetResource resource) throws IOException{
+	public void send(ResourceContext resourceContext, InternetResource resource)
+			throws IOException {
+		FacesContext facesContext = FacesContext.getCurrentInstance();
+		PhaseListener[] phaseListeners = null;
+		PhaseEvent renderViewEvent = null;
+		if (null != facesContext) {
+			Lifecycle facesLifecycle = getFacesLifecycle();
+			phaseListeners = facesLifecycle.getPhaseListeners();
+			PhaseEvent restoreViewEvent = new PhaseEvent(facesContext,
+					PhaseId.RESTORE_VIEW, this);
+			// Invoke before restore view phase listeners
+			for (int i = 0; i < phaseListeners.length; i++) {
+				PhaseListener phaseListener = phaseListeners[i];
+				if (PhaseId.RESTORE_VIEW.equals(phaseListener.getPhaseId())
+						|| PhaseId.ANY_PHASE.equals(phaseListener.getPhaseId())) {
+					try {
+						phaseListener.beforePhase(restoreViewEvent);
+
+					} catch (Exception e) {
+						_log.error("Exception in PhaseListener, restore view : beforePhase", e);
+					}
+				}
+			}
+			// Invoke after restore view phase listeners
+			for (int i = phaseListeners.length - 1; i > 0; i--) {
+				PhaseListener phaseListener = phaseListeners[i];
+				if (PhaseId.RESTORE_VIEW.equals(phaseListener.getPhaseId())
+						|| PhaseId.ANY_PHASE.equals(phaseListener.getPhaseId())) {
+					try {
+						phaseListener.afterPhase(restoreViewEvent);
+
+					} catch (Exception e) {
+						_log.error("Exception in PhaseListener, restore view : afterPhase", e);
+					}
+				}
+			}
+			// Invoke before render view phase listeners
+			renderViewEvent = new PhaseEvent(facesContext,
+					PhaseId.RENDER_RESPONSE, this);
+			for (int i = 0; i < phaseListeners.length; i++) {
+				PhaseListener phaseListener = phaseListeners[i];
+				if (PhaseId.RENDER_RESPONSE.equals(phaseListener.getPhaseId())
+						|| PhaseId.ANY_PHASE.equals(phaseListener.getPhaseId())) {
+					try {
+						phaseListener.beforePhase(renderViewEvent);
+
+					} catch (Exception e) {
+						_log.error("Exception in PhaseListener, render view : beforePhase", e);
+					}
+				}
+			}
+		}
 		resource.sendHeaders(resourceContext);
 		resource.send(resourceContext);
+		if (null != facesContext) {
+			// Invoke after restore view phase listeners
+			for (int i = phaseListeners.length - 1; i > 0; i--) {
+				PhaseListener phaseListener = phaseListeners[i];
+				if (PhaseId.RENDER_RESPONSE.equals(phaseListener.getPhaseId())
+						|| PhaseId.ANY_PHASE.equals(phaseListener.getPhaseId())) {
+					try {
+						phaseListener.afterPhase(renderViewEvent);
+
+					} catch (Exception e) {
+						_log.error("Exception in PhaseListener, render view : afterPhase", e);
+					}
+				}
+			}
+		}
 	}
 
+	protected synchronized Lifecycle getFacesLifecycle() {
+		if (lifecycle == null) {
+			// Acquire our Lifecycle instance
+			LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder
+					.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+			lifecycle = lifecycleFactory
+					.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
+		}
+
+		return lifecycle;
+	}
 }

Added: trunk/samples/seamEAR/ejbs/src/main/java/org/richfaces/seam/Media.java
===================================================================
--- trunk/samples/seamEAR/ejbs/src/main/java/org/richfaces/seam/Media.java	                        (rev 0)
+++ trunk/samples/seamEAR/ejbs/src/main/java/org/richfaces/seam/Media.java	2007-08-29 00:17:07 UTC (rev 2556)
@@ -0,0 +1,19 @@
+package org.richfaces.seam;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.ejb.Local;
+
+ at Local
+public interface Media {
+
+	public void paint(OutputStream out, Object data) throws IOException;
+
+	public  void initData();
+
+	public void setData(MediaData data);
+
+	public MediaData getData();
+
+}


Property changes on: trunk/samples/seamEAR/ejbs/src/main/java/org/richfaces/seam/Media.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Revision Author

Added: trunk/samples/seamEAR/ejbs/src/main/java/org/richfaces/seam/MediaBean.java
===================================================================
--- trunk/samples/seamEAR/ejbs/src/main/java/org/richfaces/seam/MediaBean.java	                        (rev 0)
+++ trunk/samples/seamEAR/ejbs/src/main/java/org/richfaces/seam/MediaBean.java	2007-08-29 00:17:07 UTC (rev 2556)
@@ -0,0 +1,64 @@
+package org.richfaces.seam;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.ejb.Stateless;
+import javax.imageio.ImageIO;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Factory;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Out;
+
+ at Stateless
+ at Name("media")
+public class MediaBean implements Media {
+	
+	private MediaData data;
+
+	/**
+	 * @return the data
+	 */
+	@Out
+	public MediaData getData() {
+		return data;
+	}
+
+	/**
+	 * @param data the data to set
+	 */
+	public void setData(MediaData data) {
+		this.data = data;
+	}
+	
+	@Factory(value="data")
+	public void initData(){
+		data= new MediaData();
+		data.setWidth(100);
+		data.setHeight(100);
+		data.setBackground(Color.BLUE);
+		data.setDrawColor(Color.RED);
+	}
+
+	public void paint(OutputStream out, Object data) throws IOException{
+		if (data instanceof MediaData) {
+			
+		MediaData paintData = (MediaData) data;
+		BufferedImage img = new BufferedImage(paintData.getWidth(),paintData.getHeight(),BufferedImage.TYPE_INT_RGB);
+		Graphics2D graphics2D = img.createGraphics();
+		graphics2D.setBackground(paintData.getBackground());
+		graphics2D.setColor(paintData.getDrawColor());
+		graphics2D.clearRect(0,0,paintData.getWidth(),paintData.getHeight());
+		graphics2D.drawLine(5,5,paintData.getWidth()-5,paintData.getHeight()-5);
+		graphics2D.drawChars(new String("RichFaces").toCharArray(),0,9,40,15);
+		graphics2D.drawChars(new String("mediaOutput").toCharArray(),0,11,5,45);
+		
+		ImageIO.write(img,"jpeg",out);
+		
+		}
+	}
+}
\ No newline at end of file


Property changes on: trunk/samples/seamEAR/ejbs/src/main/java/org/richfaces/seam/MediaBean.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Revision Author

Added: trunk/samples/seamEAR/ejbs/src/main/java/org/richfaces/seam/MediaData.java
===================================================================
--- trunk/samples/seamEAR/ejbs/src/main/java/org/richfaces/seam/MediaData.java	                        (rev 0)
+++ trunk/samples/seamEAR/ejbs/src/main/java/org/richfaces/seam/MediaData.java	2007-08-29 00:17:07 UTC (rev 2556)
@@ -0,0 +1,39 @@
+package org.richfaces.seam;
+
+import java.awt.Color;
+import java.io.Serializable;
+
+public class MediaData implements Serializable{
+
+	private static final long serialVersionUID = 1L;
+	Integer Width=110;
+	Integer Height=50;
+	Color Background=new Color(0,0,0);
+	Color DrawColor=new Color(255,255,255);
+	public MediaData() {
+	}
+	public Color getBackground() {
+		return Background;
+	}
+	public void setBackground(Color background) {
+		Background = background;
+	}
+	public Color getDrawColor() {
+		return DrawColor;
+	}
+	public void setDrawColor(Color drawColor) {
+		DrawColor = drawColor;
+	}
+	public Integer getHeight() {
+		return Height;
+	}
+	public void setHeight(Integer height) {
+		Height = height;
+	}
+	public Integer getWidth() {
+		return Width;
+	}
+	public void setWidth(Integer width) {
+		Width = width;
+	}
+}
\ No newline at end of file


Property changes on: trunk/samples/seamEAR/ejbs/src/main/java/org/richfaces/seam/MediaData.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Revision Author

Modified: trunk/samples/seamEAR/wars/seamWebapp/pom.xml
===================================================================
--- trunk/samples/seamEAR/wars/seamWebapp/pom.xml	2007-08-28 23:44:27 UTC (rev 2555)
+++ trunk/samples/seamEAR/wars/seamWebapp/pom.xml	2007-08-29 00:17:07 UTC (rev 2556)
@@ -45,6 +45,11 @@
 			<version>3.1.0-SNAPSHOT</version>
 		</dependency>
 		<dependency>
+			<groupId>org.richfaces.ui</groupId>
+			<artifactId>richfaces-ui</artifactId>
+			<version>3.1.0-SNAPSHOT</version>
+		</dependency>
+		<dependency>
 			<groupId>org.richfaces.framework</groupId>
 			<artifactId>richfaces-api</artifactId>
 			<version>3.1.0-SNAPSHOT</version>

Modified: trunk/samples/seamEAR/wars/seamWebapp/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/samples/seamEAR/wars/seamWebapp/src/main/webapp/WEB-INF/web.xml	2007-08-28 23:44:27 UTC (rev 2555)
+++ trunk/samples/seamEAR/wars/seamWebapp/src/main/webapp/WEB-INF/web.xml	2007-08-29 00:17:07 UTC (rev 2556)
@@ -13,7 +13,7 @@
  <!-- Facelets development mode (disable in production) -->
  <context-param>
   <param-name>facelets.DEVELOPMENT</param-name>
-  <param-value>true</param-value>
+  <param-value>false</param-value>
  </context-param>
  <!-- JSF -->
  <context-param>

Added: trunk/samples/seamEAR/wars/seamWebapp/src/main/webapp/pages/mediaOutput.xhtml
===================================================================
--- trunk/samples/seamEAR/wars/seamWebapp/src/main/webapp/pages/mediaOutput.xhtml	                        (rev 0)
+++ trunk/samples/seamEAR/wars/seamWebapp/src/main/webapp/pages/mediaOutput.xhtml	2007-08-29 00:17:07 UTC (rev 2556)
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
+                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:s="http://jboss.com/products/seam/taglib"
+      xmlns:h="http://java.sun.com/jsf/html"
+      xmlns:a4j="http://richfaces.org/a4j"
+      xmlns:rich="http://richfaces.org/rich"
+      xmlns:f="http://java.sun.com/jsf/core">
+
+   <head>
+      <title>Paint image in a4j:mediaOutput</title>
+   </head>
+   <body>
+      <f:view>
+         <h:form>
+               <h:panelGrid columns="2">
+                  Width: <h:inputText value="#{data.width}" required="true"/>
+                  Height: <h:inputText value="#{data.height}" required="true"/>
+               </h:panelGrid>
+               <a4j:mediaOutput mimeType="image/jpeg" createContent="#{media.paint}" session="true" value="#{data}"
+               cacheable="false" uriAttribute="src" element="img" style="width:#{data.width};height:#{data.height}"/>
+            <h:messages/>
+            <h:commandButton value="Paint" />
+         </h:form>
+      </f:view>
+   </body>
+
+</html>
\ No newline at end of file


Property changes on: trunk/samples/seamEAR/wars/seamWebapp/src/main/webapp/pages/mediaOutput.xhtml
___________________________________________________________________
Name: svn:mime-type
   + text/plain




More information about the richfaces-svn-commits mailing list