You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ca...@apache.org on 2007/02/06 14:21:07 UTC

svn commit: r504129 - /myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/form/HtmlFormRenderer.java

Author: cagatay
Date: Tue Feb  6 05:21:06 2007
New Revision: 504129

URL: http://svn.apache.org/viewvc?view=rev&rev=504129
Log:
Add client side validation/conversion features

Modified:
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/form/HtmlFormRenderer.java

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/form/HtmlFormRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/form/HtmlFormRenderer.java?view=diff&rev=504129&r1=504128&r2=504129
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/form/HtmlFormRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/form/HtmlFormRenderer.java Tue Feb  6 05:21:06 2007
@@ -18,10 +18,14 @@
  */
 package org.apache.myfaces.custom.form;
 
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
 import javax.faces.component.UIForm;
 import javax.faces.context.FacesContext;
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.myfaces.custom.clientvalidation.common.CVUtils;
 import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlFormRendererBase;
 
 /**
@@ -31,7 +35,8 @@
  */
 public class HtmlFormRenderer extends HtmlFormRendererBase
 {
-
+	private static String CLIENT_VALIDATON_SCRIPT = "return tomahawk.executeClientLifeCycle();";
+	
     /**
      * @see org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlFormRendererBase#getActionUrl(javax.faces.context.FacesContext, javax.faces.component.UIForm )
      */
@@ -120,5 +125,39 @@
 
         return "post";
     }
+    
+    public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
+    	if(CVUtils.isCVEnabled()) {
+    		if(!isDecorated(facesContext, component))
+    		decorateOnSubmit(facesContext, component);
+    	}
+    	super.encodeBegin(facesContext, component);
+    }
+    
+    public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
+    	super.encodeEnd(facesContext, component);
+    	if(CVUtils.isCVEnabled()) {
+    		CVUtils.encodeJavascript(facesContext);
+			CVUtils.queueCVCalls(facesContext.getViewRoot());
+			CVUtils.encodeValidationScript(facesContext);
+    	}
+    }
+    
+    private boolean isDecorated(FacesContext facesContext, UIComponent child) {
+		String onSubmit= (String) child.getAttributes().get("onsubmit");
+		
+		if(onSubmit == null || onSubmit.indexOf(CLIENT_VALIDATON_SCRIPT) == -1)
+			return false;
+		else
+			return true;
+	}
+	
+	private void decorateOnSubmit(FacesContext facesContext, UIComponent child) {
+		String onSubmitEvent = (String) child.getAttributes().get("onsubmit");
+		if(onSubmitEvent == null)
+			child.getAttributes().put("onsubmit", CLIENT_VALIDATON_SCRIPT);
+		else
+			child.getAttributes().put("onsubmit", onSubmitEvent + ";" + CLIENT_VALIDATON_SCRIPT);
+	}
 
 }