[richfaces-svn-commits] JBoss Rich Faces SVN: r2318 - in trunk: samples/effect-sample and 2 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Fri Aug 17 09:52:50 EDT 2007


Author: nbelaevski
Date: 2007-08-17 09:52:50 -0400 (Fri, 17 Aug 2007)
New Revision: 2318

Modified:
   trunk/framework/impl/src/main/java/org/richfaces/json/JSONTokener.java
   trunk/samples/effect-sample/
   trunk/ui/effect/src/main/java/org/richfaces/renderkit/EffectRendererBase.java
   trunk/ui/effect/src/main/templates/effect.jspx
Log:
http://jira.jboss.com/jira/browse/RF-586 fixed

Modified: trunk/framework/impl/src/main/java/org/richfaces/json/JSONTokener.java
===================================================================
--- trunk/framework/impl/src/main/java/org/richfaces/json/JSONTokener.java	2007-08-17 13:18:25 UTC (rev 2317)
+++ trunk/framework/impl/src/main/java/org/richfaces/json/JSONTokener.java	2007-08-17 13:52:50 UTC (rev 2318)
@@ -478,4 +478,11 @@
     public String toString() {
         return " at character " + this.myIndex + " of " + this.mySource;
     }
+    
+    /**
+     * @return current index
+     */
+    public int getMyIndex() {
+		return myIndex;
+	}
 }
\ No newline at end of file


Property changes on: trunk/samples/effect-sample
___________________________________________________________________
Name: svn:ignore
   - target

   + target
.settings
.classpath
.project


Modified: trunk/ui/effect/src/main/java/org/richfaces/renderkit/EffectRendererBase.java
===================================================================
--- trunk/ui/effect/src/main/java/org/richfaces/renderkit/EffectRendererBase.java	2007-08-17 13:18:25 UTC (rev 2317)
+++ trunk/ui/effect/src/main/java/org/richfaces/renderkit/EffectRendererBase.java	2007-08-17 13:52:50 UTC (rev 2318)
@@ -4,18 +4,14 @@
 package org.richfaces.renderkit;
 
 import java.io.IOException;
-import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 
-import org.ajax4jsf.javascript.JSEncoder;
-import org.ajax4jsf.renderkit.ComponentsVariableResolver;
 import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
 import org.richfaces.component.UIEffect;
-import org.richfaces.json.JSONException;
-import org.richfaces.json.JSONMap;
+import org.richfaces.json.JSONTokener;
 
 /**
  * @author Nick Belaevski
@@ -46,32 +42,91 @@
 	}
 	
 	public String convertParameters(FacesContext context, UIEffect effect) throws IOException {
-		JSEncoder encoder = new JSEncoder();
 		String params = effect.getParams();
 		if (params == null) {
 			return null;
 		}
 
+		StringBuffer buffer = new StringBuffer("{" + params + "}");
 		try {
-			JSONMap map = new JSONMap("{" + params + "}");
-			Object id = map.get("id");
-			if (id != null) {
-				UIComponent component = effect.findComponent(id.toString());
-				if (component != null) {
-					id = component.getClientId(context);
-				}
-
-				map.put("id", null);
-			}
-
-			ComponentsVariableResolver.getVariables(this, effect).setVariable("pmId", id);
-
-			return map.getString();
-		} catch (JSONException e) {
+			replace(context, effect, buffer);
+			return buffer.toString();
+		} catch (Exception e) {
 			IOException exception = new IOException(e.getMessage());
 			exception.initCause(e);
 			
 			throw exception;
 		}
 	}
+	
+	private static void replace(FacesContext context, UIComponent effect, StringBuffer s) throws Exception {
+		JSONTokener x = new JSONTokener(s.toString());
+        char c;
+        String key;
+
+        if (x.nextClean() != '{') {
+            throw x.syntaxError("A JSONObject text must begin with '{'");
+        }
+        for (;;) {
+            int idx;
+        	c = x.nextClean();
+            switch (c) {
+            case 0:
+                throw x.syntaxError("A JSONObject text must end with '}'");
+            case '}':
+                return;
+            default:
+                x.back();
+            	idx = x.getMyIndex();
+            	//System.out.println(s.substring(x.getMyIndex()));
+                key = x.nextValue().toString();
+            }
+
+            /*
+             * The key is followed by ':'. We will also tolerate '=' or '=>'.
+             */
+
+            c = x.nextClean();
+            if (c == '=') {
+                if (x.next() != '>') {
+                    x.back();
+                }
+            } else if (c != ':') {
+                throw x.syntaxError("Expected a ':' after a key");
+            }
+            
+            if ("id".equals(key)) {
+            	Object value = x.nextValue();
+				UIComponent component = effect.findComponent(value.toString());
+				if (component != null) {
+					value = component.getClientId(context);
+				}
+
+            	
+            	s.replace(idx, x.getMyIndex(), "'id': " + value);
+            	
+            	return ;
+            } else {
+            	x.nextValue();
+            }
+
+            /*
+             * Pairs are separated by ','. We will also tolerate ';'.
+             */
+
+            switch (x.nextClean()) {
+            case ';':
+            case ',':
+                if (x.nextClean() == '}') {
+                    return;
+                }
+                x.back();
+                break;
+            case '}':
+                return;
+            default:
+                throw x.syntaxError("Expected a ',' or '}'");
+            }
+        }
+	}	
 }

Modified: trunk/ui/effect/src/main/templates/effect.jspx
===================================================================
--- trunk/ui/effect/src/main/templates/effect.jspx	2007-08-17 13:18:25 UTC (rev 2317)
+++ trunk/ui/effect/src/main/templates/effect.jspx	2007-08-17 13:52:50 UTC (rev 2318)
@@ -16,7 +16,7 @@
 	<c:set var="name" value="#{component.attributes['name']}"/>
 	<c:set var="type" value="#{component.attributes['type']}"/>
 	<c:set var="targetId" value="#{component.attributes['targetId']}"/>
-	<c:set var="params" value="#{component.attributes['params']}"/>
+	<c:set var="params" value="#{this:convertParameters(context, component)}"/>
 	<h:scripts>new org.ajax4jsf.javascript.PrototypeScript(),scripts/scriptaculous/scriptaculous.js,scripts/scriptaculous/effects.js,/org/richfaces/renderkit/html/script/processEffect.js</h:scripts>
          
 
@@ -63,13 +63,6 @@
 		variables.setVariable("typePart","{}");
 	}
 
-	String params = (String) variables.getVariable("params");
-	if (!"".equals(params)) {
-		variables.setVariable("paramsPart","{"+params+"}");
-	} else {
-		variables.setVariable("paramsPart","{}");
-	}
-
 	String event = (String) variables.getVariable("event");
         String name = (String)variables.getVariable("name");
         Boolean needsFunction = new Boolean(! "".equals(name) && "".equals(event));
@@ -82,7 +75,7 @@
 <c:if test="#{needsFunction}">
 <script type="text/javascript" x:passThruWithExclusions="name,type,for">
  //<![CDATA[
-#{name} = function () { return Richfaces.processEffect(Object.extend(Object.extend( Object.extend(#{typePart},#{forPart}), Object.extend (#{targetPart},#{paramsPart})), arguments[0]||{})); };
+#{name} = function () { return Richfaces.processEffect(Object.extend(Object.extend( Object.extend(#{typePart},#{forPart}), Object.extend (#{targetPart},#{params})), arguments[0]||{})); };
 //]]>
 </script>
 </c:if>
@@ -95,7 +88,7 @@
 //pm.id = #{this:convertElementParameter(pmId)};
 if (typeof #{attachObj} == 'object') {pm.attachId= #{attachObj};if (#{targetObj}=='') pm.targetId=#{attachObj}; };
 if (typeof #{targetObj} == 'object') pm.targetId= #{targetObj};
-pm = Object.extend(pm, {#{params}});
+pm = Object.extend(pm, #{params});
 var ename = Richfaces.effectEventOnOut('#{event}');
 var bindedFunction = function(event){ return Richfaces.processEffect(this); }.bindAsEventListener(pm);
 Event.observe(pm.attachId,ename, bindedFunction, pm.useCapture||false);




More information about the richfaces-svn-commits mailing list