[richfaces-svn-commits] JBoss Rich Faces SVN: r13456 - in trunk/test-applications/realworld2/web: src/main/java/org/richfaces/realworld/util and 5 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Thu Apr 9 07:41:04 EDT 2009


Author: nbelaevski
Date: 2009-04-09 07:41:03 -0400 (Thu, 09 Apr 2009)
New Revision: 13456

Added:
   trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/ActionMapperTagHandler.java
   trunk/test-applications/realworld2/web/src/main/webapp/WEB-INF/tags/templates/
   trunk/test-applications/realworld2/web/src/main/webapp/WEB-INF/tags/templates/button.xhtml
   trunk/test-applications/realworld2/web/src/main/webapp/img/shell/button_press.png
   trunk/test-applications/realworld2/web/src/main/webapp/scripts/buttons.js
Modified:
   trunk/test-applications/realworld2/web/pom.xml
   trunk/test-applications/realworld2/web/src/main/webapp/WEB-INF/tags/realWorld-taglib.xml
   trunk/test-applications/realworld2/web/src/main/webapp/stylesheet/realworld.css
Log:
richx:commandButton made Facelets tag

Modified: trunk/test-applications/realworld2/web/pom.xml
===================================================================
--- trunk/test-applications/realworld2/web/pom.xml	2009-04-09 11:11:52 UTC (rev 13455)
+++ trunk/test-applications/realworld2/web/pom.xml	2009-04-09 11:41:03 UTC (rev 13456)
@@ -12,6 +12,12 @@
     <packaging>war</packaging>
 	<dependencies>
 	<dependency>
+		<groupId>javax.el</groupId>
+		<artifactId>el-api</artifactId>
+		<version>1.0</version>
+		<scope>provided</scope>
+	</dependency>
+	<dependency>
 			<groupId>com.drewnoakes</groupId>
 			<artifactId>metadata-extractor</artifactId>
 			<version>2.4.0-beta1</version>

Added: trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/ActionMapperTagHandler.java
===================================================================
--- trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/ActionMapperTagHandler.java	                        (rev 0)
+++ trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/ActionMapperTagHandler.java	2009-04-09 11:41:03 UTC (rev 13456)
@@ -0,0 +1,201 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2006 - original idea by Andrew Robinson
+ * http://andrewfacelets.blogspot.com/2006/06/creating-composite-controls-with-jsf.html
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+
+package org.richfaces.realworld.util;
+
+import java.io.IOException;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ExpressionFactory;
+import javax.el.MethodExpression;
+import javax.el.MethodInfo;
+import javax.el.ValueExpression;
+import javax.el.VariableMapper;
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+import javax.faces.event.ActionEvent;
+
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.FaceletException;
+import com.sun.facelets.el.VariableMapperWrapper;
+import com.sun.facelets.tag.TagConfig;
+import com.sun.facelets.tag.TagHandler;
+
+public class ActionMapperTagHandler extends TagHandler {
+
+	private static final Class<?>[] ACTION_PARAM_TYPES = new Class[0];
+
+	private static final Class<?>[] ACTION_LISTENER_PARAM_TYPES = new Class[] {ActionEvent.class};
+
+	private static final MethodInfo NOOP_ACTION_INFO = new MethodInfo("$$$noOpAction", String.class, ACTION_PARAM_TYPES);
+
+	private static final MethodExpression NOOP_ACTION_EXPRESSION = new MethodExpression() {
+
+		/**
+		 * 
+		 */
+		private static final long serialVersionUID = 8901807727474303033L;
+
+
+		@Override
+		public MethodInfo getMethodInfo(ELContext context) {
+			return NOOP_ACTION_INFO;
+		}
+
+		@Override
+		public Object invoke(ELContext context, Object[] params) {
+			return null;
+		}
+
+		@Override
+		public String getExpressionString() {
+			return "#{" + NOOP_ACTION_INFO.getName() + "}";
+		}
+
+		@Override
+		public boolean isLiteralText() {
+			return false;
+		}
+
+		@Override
+		public boolean equals(Object obj) {
+			return this == obj;
+		}
+
+		@Override
+		public int hashCode() {
+			return NOOP_ACTION_INFO.hashCode();
+		}
+		
+	};
+	
+	private static final MethodInfo NOOP_ACTION_LISTENER_INFO = new MethodInfo("$$$noOpActionListener", Void.class, ACTION_LISTENER_PARAM_TYPES);
+
+	private static final MethodExpression NOOP_ACTION_LISTENER_EXPRESSION = new MethodExpression() {
+		
+		/**
+		 * 
+		 */
+		private static final long serialVersionUID = 6246200728401095532L;
+
+		@Override
+		public MethodInfo getMethodInfo(ELContext context) {
+			return NOOP_ACTION_LISTENER_INFO;
+		}
+
+		@Override
+		public Object invoke(ELContext context, Object[] params) {
+			return null;
+		}
+
+		@Override
+		public String getExpressionString() {
+			return "#{" + NOOP_ACTION_LISTENER_INFO.getName() + "}";
+		}
+
+		@Override
+		public boolean isLiteralText() {
+			return false;
+		}
+
+		@Override
+		public boolean equals(Object obj) {
+			return this == obj;
+		}
+
+		@Override
+		public int hashCode() {
+			return NOOP_ACTION_LISTENER_INFO.hashCode();
+		}
+	};
+
+	private static final String ACTION = "action";
+
+	private static final String ACTION_LISTENER = "actionListener";
+
+	private static final String MAPPED_ACTION = "mappedAction";
+	
+	private static final String MAPPED_ACTION_LISTENER = "mappedActionListener";
+
+	public ActionMapperTagHandler(TagConfig config) {
+		super(config);
+	}
+
+	private MethodExpression remap(FaceletContext faceletContext, String varName, 
+			Class<?> expectedReturnType, Class<?>[] expectedParamTypes) {
+		
+		MethodExpression result = null;
+		
+		VariableMapper mapper = faceletContext.getVariableMapper();
+		ValueExpression valueExpression = mapper.resolveVariable(varName);
+		if (valueExpression != null) {
+			ExpressionFactory ef = faceletContext.getExpressionFactory();
+			ELContext elContext = faceletContext.getFacesContext().getELContext();
+			
+			result = ef.createMethodExpression(elContext, valueExpression.getExpressionString(), 
+				expectedReturnType, expectedParamTypes);
+		}
+		
+		return result;
+	}
+	
+	public void apply(FaceletContext ctx, UIComponent parent)
+			throws IOException, FacesException, FaceletException, ELException {
+
+		MethodExpression actionExpression = remap(ctx, ACTION, String.class, ACTION_PARAM_TYPES);
+		MethodExpression actionListenerExpression = remap(ctx, ACTION_LISTENER, null, ACTION_LISTENER_PARAM_TYPES);
+		
+		if (actionExpression != null || actionListenerExpression != null) {
+			VariableMapper initialVarMapper = ctx.getVariableMapper();
+			try {
+				VariableMapperWrapper varMapper = new VariableMapperWrapper(initialVarMapper);
+			
+				if (actionExpression == null) {
+					actionExpression = NOOP_ACTION_EXPRESSION;
+				}
+				
+				varMapper.setVariable(MAPPED_ACTION, 
+					ctx.getExpressionFactory().createValueExpression(actionExpression, 
+						MethodExpression.class));
+
+				if (actionListenerExpression == null) {
+					actionListenerExpression = NOOP_ACTION_LISTENER_EXPRESSION;
+				}
+
+				varMapper.setVariable(MAPPED_ACTION_LISTENER, 
+						ctx.getExpressionFactory().createValueExpression(actionListenerExpression, 
+							MethodExpression.class));
+				
+				ctx.setVariableMapper(varMapper);
+				
+				nextHandler.apply(ctx, parent);
+				
+			} finally {
+				ctx.setVariableMapper(initialVarMapper);
+			}
+		} else {
+			nextHandler.apply(ctx, parent);
+		}
+	}
+
+}

Modified: trunk/test-applications/realworld2/web/src/main/webapp/WEB-INF/tags/realWorld-taglib.xml
===================================================================
--- trunk/test-applications/realworld2/web/src/main/webapp/WEB-INF/tags/realWorld-taglib.xml	2009-04-09 11:11:52 UTC (rev 13455)
+++ trunk/test-applications/realworld2/web/src/main/webapp/WEB-INF/tags/realWorld-taglib.xml	2009-04-09 11:41:03 UTC (rev 13456)
@@ -6,9 +6,10 @@
    <namespace>http://richfaces.org/richx</namespace>
 	<tag>
 	   <tag-name>commandButton</tag-name>
-	   <component>
-    	<component-type>org.ajax4jsf.CommandButton</component-type>
-	   	<renderer-type>org.ajax4jsf.components.RealworldAjaxCommandButtonRenderer</renderer-type>
-	   </component>
+	   <source>templates/button.xhtml</source>
 	</tag>
+	<tag>
+		<tag-name>actionMapper</tag-name>
+		<handler-class>org.richfaces.realworld.util.ActionMapperTagHandler</handler-class>
+	</tag>
 </facelet-taglib>
\ No newline at end of file

Added: trunk/test-applications/realworld2/web/src/main/webapp/WEB-INF/tags/templates/button.xhtml
===================================================================
--- trunk/test-applications/realworld2/web/src/main/webapp/WEB-INF/tags/templates/button.xhtml	                        (rev 0)
+++ trunk/test-applications/realworld2/web/src/main/webapp/WEB-INF/tags/templates/button.xhtml	2009-04-09 11:41:03 UTC (rev 13456)
@@ -0,0 +1,36 @@
+<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
+                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<ui:composition xmlns="http://www.w3.org/1999/xhtml"
+	xmlns:s="http://jboss.com/products/seam/taglib"
+	xmlns:c="http://java.sun.com/jstl/core"
+	xmlns:ui="http://java.sun.com/jsf/facelets"
+	xmlns:f="http://java.sun.com/jsf/core"
+	xmlns:h="http://java.sun.com/jsf/html"
+	xmlns:rich="http://richfaces.org/rich"
+	xmlns:a4j="http://richfaces.org/a4j"
+	xmlns:richx="http://richfaces.org/richx">
+
+	<a4j:loadScript src="/scripts/buttons.js" />
+
+	<richx:actionMapper>
+		<a4j:outputPanel id="#{myid}" layout="block" style="#{style}" styleClass="realworldButton #{styleClass}" lang="#{lang}" dir="#{dir}" title="#{title}" 
+			rendered="#{empty rendered or rendered}"
+			onmousedown="RF_RW_DEMO.toPressed(this)" onmouseup="RF_RW_DEMO.toReleased(this)" onmouseout="RF_RW_DEMO.toReleased(this)">
+		
+				<h:graphicImage value="/img/shell/button.png" alt="" />
+				<h:graphicImage value="/img/shell/button_press.png" style="display: none;" alt="" />
+	
+				<div>#{value}</div>
+	
+				<a4j:commandButton accesskey="#{accesskey}" ajaxSingle="#{ajaxSingle}" alt="#{alt}" type="image" image="/img/shell/spacer.gif" 
+					actionListener="#{mappedActionListener}" action="#{mappedAction}" bypassUpdates="#{bypassUpdates}" data="#{data}" disabled="#{disabled}"
+					eventsQueue="#{eventsQueue}" focus="#{focus}" ignoreDupResponses="#{ignoreDupResponses}" immediate="#{immediate}" limitToList="#{limitToList}"
+					onbeforedomupdate="#{onbeforedomupdate}" timeout="#{timeout}" tabindex="#{tabindex}" status="#{status}" similarityGroupingId="#{similarityGroupingId}" 
+					reRender="#{reRender}" requestDelay="#{requestDelay}" process="#{process}" oncomplete="#{oncomplete}" 
+					onblur="#{onblur}" onclick="#{onclick}" ondblclick="#{ondblclick}" onfocus="#{onfocus}" onkeydown="#{onkeydown}" onkeypress="#{onkeypress}" onkeyup="#{onkeyup}" 
+					onmousedown="#{onmousedown}" onmousemove="#{onmousemove}" onmouseout="#{onmouseout}" onmouseover="#{onmouseover}" onmouseup="#{onmouseup}" />
+	
+		</a4j:outputPanel>
+	</richx:actionMapper>
+
+</ui:composition>
\ No newline at end of file

Added: trunk/test-applications/realworld2/web/src/main/webapp/img/shell/button_press.png
===================================================================
(Binary files differ)


Property changes on: trunk/test-applications/realworld2/web/src/main/webapp/img/shell/button_press.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/test-applications/realworld2/web/src/main/webapp/scripts/buttons.js
===================================================================
--- trunk/test-applications/realworld2/web/src/main/webapp/scripts/buttons.js	                        (rev 0)
+++ trunk/test-applications/realworld2/web/src/main/webapp/scripts/buttons.js	2009-04-09 11:41:03 UTC (rev 13456)
@@ -0,0 +1,21 @@
+if (!window.RF_RW_DEMO) {
+	window.RF_RW_DEMO = {};
+}
+
+(function(demo) {
+	var findButtons = function(elt) {
+		return $(elt).select('img');
+	};
+	
+	demo.toPressed = function(elt) {
+		var buttons = findButtons(elt);
+		buttons[1].show();
+		buttons[0].hide();
+	};
+	
+	demo.toReleased = function(elt) {
+		var buttons = findButtons(elt);
+		buttons[0].show();
+		buttons[1].hide();
+	};
+}(RF_RW_DEMO));

Modified: trunk/test-applications/realworld2/web/src/main/webapp/stylesheet/realworld.css
===================================================================
--- trunk/test-applications/realworld2/web/src/main/webapp/stylesheet/realworld.css	2009-04-09 11:11:52 UTC (rev 13455)
+++ trunk/test-applications/realworld2/web/src/main/webapp/stylesheet/realworld.css	2009-04-09 11:41:03 UTC (rev 13456)
@@ -814,28 +814,40 @@
 	text-decoration:none;
 }
 
+
 .realworldButton {
-	margin : 0px 0px 0px 0px; 
-	position : relative; 
-	width : 103px; 
-	height : 28px; 
+	margin: 0px 0px 0px 0px; 
+	position: relative; 
+	width: 103px; 
+	height: 28px;
 	cursor: pointer;
 }
 
-.realworldButton div {
-	position : absolute; 
-	color : #ffffff; 
-	top : 7px; 
-	left : 11px; 
-	font-weight : bold;	
+.realworldButton input, .realworldButton img {
+	position: absolute; 
+	top: 0px; 
+	left: 0px;
+	width: 103px;
+	height: 28px;
 }
 
 .realworldButton img {
-	position : absolute; 
-	top : 0px; 
-	left : 0px;
+	border-width: 0px;
 }
 
+.realworldButton input {
+	outline-style: none;
+}
+
+.realworldButton div {
+	position: absolute; 
+	color: #ffffff; 
+	top: 7px; 
+	left: 0px; 
+	width: 103px; 
+	text-align: center; 
+}
+
 .album-edit-field {
 	padding-top : 8px
 }




More information about the richfaces-svn-commits mailing list