[richfaces-svn-commits] JBoss Rich Faces SVN: r14684 - in branches/community/3.3.X/framework/impl/src/main: java/org/ajax4jsf/renderkit and 1 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Sun Jun 21 09:51:29 EDT 2009


Author: nbelaevski
Date: 2009-06-21 09:51:28 -0400 (Sun, 21 Jun 2009)
New Revision: 14684

Modified:
   branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java
   branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
   branches/community/3.3.X/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
Log:
https://jira.jboss.org/jira/browse/RF-7375

Modified: branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java	2009-06-20 14:50:01 UTC (rev 14683)
+++ branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java	2009-06-21 13:51:28 UTC (rev 14684)
@@ -70,8 +70,6 @@
 
 	public static final String ROOT_ID = "_viewRoot";
 	
-	public static final String JS_NULL = "null";
-
 	private Lifecycle lifecycle;
 
 	private AjaxRegionBrige _brige;
@@ -217,9 +215,8 @@
 			AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
 			String submittedRegionClientId = ajaxContext
 					.getSubmittedRegionClientId();
-			// !submittedRegionClientId.equals(JS_NULL) - fix for myfaces 1.2.4  
 			if (ajaxContext.isAjaxRequest() && submittedRegionClientId != null && 
-							!submittedRegionClientId.equals(JS_NULL) 
+							!submittedRegionClientId.equals(ROOT_ID) 
 							&& !submittedRegionClientId.equals(getClientId(context))) {
 				invokeOnComponent(context, submittedRegionClientId, new InvokerCallbackWrapper(callback));
 			} else {
@@ -539,7 +536,7 @@
 			String submittedRegionClientId = ajaxContext
 					.getSubmittedRegionClientId();
 			boolean invoked = false; 
-			if (submittedRegionClientId != null && !submittedRegionClientId.equals(JS_NULL) && !submittedRegionClientId.equals(getClientId(context))) {
+			if (submittedRegionClientId != null && !submittedRegionClientId.equals(ROOT_ID) && !submittedRegionClientId.equals(getClientId(context))) {
 				invoked = invokeOnComponent(context, submittedRegionClientId, _ajaxInvoker);
 			} 
 			// if container not found, use Root for encode.

Modified: branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java	2009-06-20 14:50:01 UTC (rev 14683)
+++ branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java	2009-06-21 13:51:28 UTC (rev 14684)
@@ -26,7 +26,6 @@
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.Locale;
@@ -127,6 +126,8 @@
 	
 	public static final String SIMILARITY_GROUPING_ID_ATTR = "similarityGroupingId";
 
+	private static final RendererUtils rendererUtils = RendererUtils.getInstance();
+	
 	/**
 	 * Static class - protect constructor 
 	 * 
@@ -145,8 +146,24 @@
 	 */
 	public static StringBuffer buildOnClick(UIComponent uiComponent,
 			FacesContext facesContext) {
-		return buildOnEvent(uiComponent, facesContext, HTML.onclick_ATTRIBUTE);
+		
+		return buildOnClick(uiComponent, facesContext, false);
 	}
+	
+	/**
+	 * Build JavaScript onclick event for given component
+	 * 
+	 * @param uiComponent -
+	 *            component for build event
+	 * @param facesContext
+	 * @param omitDefaultActionUrl - default action URL is not encoded if parameter is true     
+	 *       
+	 * @return <code>StringBuffer</code> with Javascript code
+	 */
+	public static StringBuffer buildOnClick(UIComponent uiComponent,
+			FacesContext facesContext, boolean omitDefaultActionUrl) {
+		return buildOnEvent(uiComponent, facesContext, HTML.onclick_ATTRIBUTE, omitDefaultActionUrl);
+	}
 
 	/**
 	 * Build JavaScript event for component
@@ -160,6 +177,24 @@
 	 */
 	public static StringBuffer buildOnEvent(UIComponent uiComponent,
 			FacesContext facesContext, String eventName) {
+	
+		return buildOnEvent(uiComponent, facesContext, eventName, false);
+	}
+	
+	/**
+	 * Build JavaScript event for component
+	 * 
+	 * @param uiComponent -
+	 *            component for build event
+	 * @param facesContext
+	 * @param eventName -
+	 *            name of event
+	 * @param omitDefaultActionUrl - default action URL is not encoded if parameter is true           
+	 *           
+	 * @return <code>StringBuffer</code> with Javascript code 
+	 */
+	public static StringBuffer buildOnEvent(UIComponent uiComponent,
+			FacesContext facesContext, String eventName, boolean omitDefaultActionUrl) {
 		StringBuffer onEvent = new StringBuffer();
 		if (null != eventName) {
 			String commandOnEvent = (String) uiComponent.getAttributes().get(
@@ -182,7 +217,7 @@
 		// status - id of request status component.
 		// parameters - map of parameters name/value for append on request.
 		// ..........
-		ajaxFunction.addParameter(buildEventOptions(facesContext, uiComponent));
+		ajaxFunction.addParameter(buildEventOptions(facesContext, uiComponent, omitDefaultActionUrl));
 
 		// appendAjaxSubmitParameters(facesContext, uiComponent, onEvent);
 		ajaxFunction.appendScript(onEvent);
@@ -204,16 +239,36 @@
 		return buildEventOptions(facesContext, component, null);
 	}
 	
+	public static Map<String, Object> buildEventOptions(FacesContext facesContext,
+			UIComponent uiComponent, Map<String, Object> params) {
+		
+		return buildEventOptions(facesContext, uiComponent, params, false);
+	}
+	
+	public static Map<String, Object> buildEventOptions(FacesContext facesContext, 
+			UIComponent component, boolean omitDefaultActionUrl) {
+		
+		return buildEventOptions(facesContext, component, null, omitDefaultActionUrl);
+	}
+	
 	/**
 	 * @param facesContext
 	 * @param uiComponent
 	 * @return
 	 */
 	public static Map<String, Object> buildEventOptions(FacesContext facesContext,
-			UIComponent uiComponent, Map<String, Object> params) {
+			UIComponent uiComponent, Map<String, Object> params, boolean omitDefaultActionUrl) {
 		String clientId = uiComponent.getClientId(facesContext);
 		Map<String, Object> componentAttributes = uiComponent.getAttributes();
 		Map<String, Object> options = new HashMap<String, Object>();
+
+		UIComponent nestingContainer = (UIComponent) findAjaxContainer(
+				facesContext, uiComponent);
+		String containerClientId = nestingContainer.getClientId(facesContext);
+		if (containerClientId != null && !AjaxViewRoot.ROOT_ID.equals(containerClientId)) {
+			options.put("containerId", containerClientId);
+		}
+
 		Map<String, Object> parameters = new HashMap<String, Object>();
 		UIComponent targetComponent = (uiComponent instanceof AjaxSupport)?uiComponent.getParent():uiComponent;
 		// UIForm form = getNestingForm(uiComponent);
@@ -242,9 +297,23 @@
 		controlValue = clientId;
 		parameters.put(controlName, controlValue);
 		AjaxContext ajaxContext = AjaxContext.getCurrentInstance(facesContext);
-		// Setup action URL. For portlet environment, it will be different from
-		// page. 
-		options.put("actionUrl", ajaxContext.getAjaxActionURL(facesContext));
+		
+		String ajaxActionURL = ajaxContext.getAjaxActionURL(facesContext);
+		if (omitDefaultActionUrl) {
+			UIComponent form = getNestingForm(uiComponent);
+			if (form != null && !rendererUtils.isBooleanAttribute(form, "ajaxSubmit")) {
+				if (rendererUtils.getActionUrl(facesContext).equals(ajaxActionURL)) {
+					ajaxActionURL = null;
+				}
+			}
+		}
+
+		if (ajaxActionURL != null) {
+			// Setup action URL. For portlet environment, it will be different from
+			// page. 
+			options.put("actionUrl", ajaxActionURL);
+		}
+		
 		// Add application-wide Ajax parameters
 		parameters.putAll(ajaxContext.getCommonAjaxParameters());
 		// add child parameters
@@ -399,18 +468,6 @@
 	public static JSFunction buildAjaxFunction(UIComponent uiComponent,
 			FacesContext facesContext, String functionName) {
 		JSFunction ajaxFunction = new JSFunction(functionName);
-		UIComponent nestingContainer = (UIComponent) findAjaxContainer(
-				facesContext, uiComponent);
-		
-		
-		String clientId = nestingContainer.getClientId(facesContext);
-		if (clientId != null) {
-		    ajaxFunction.addParameter(clientId);
-		} else {
-		    // fix for myfaces 1.2.4
-		    ajaxFunction.addParameter(JSReference.NULL);   
-		}
-				
 		// build form name or ActionUrl for script
 		UIComponent nestingForm = getNestingForm(uiComponent);
 		if (null == nestingForm) {

Modified: branches/community/3.3.X/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js	2009-06-20 14:50:01 UTC (rev 14683)
+++ branches/community/3.3.X/framework/impl/src/main/javascript/ajaxjsf/JSFAJAX.js	2009-06-21 13:51:28 UTC (rev 14684)
@@ -10,6 +10,8 @@
 
 A4J.AJAX = {};
 
+A4J.AJAX.VIEW_ROOT_ID = "_viewRoot";
+
 A4J.AJAX.Stub = function() {};
 
 A4J.AJAX.isWebKit = navigator.userAgent.search(/( AppleWebKit\/)([^ ]+)/) != -1;
@@ -671,7 +673,7 @@
  * 
  * 
  */
-A4J.AJAX.Poll =  function( containerId, form, options ) {
+A4J.AJAX.Poll =  function(form, options) {
 	A4J.AJAX.StopPoll(options.pollId);
 	if(!options.onerror){
 	  options.onerror = function(req,status,message){
@@ -679,13 +681,13 @@
 			A4J.AJAX.onError(req,status,message);
     	}		
 		// For error, re-submit request.
-    	A4J.AJAX.Poll(containerId,form,options);
+    	A4J.AJAX.Poll(form,options);
 	  };
 	}
 	
 	if (!options.onqueuerequestdrop) {
 		options.onqueuerequestdrop = function() {
-	    	A4J.AJAX.Poll(containerId,form,options);
+	    	A4J.AJAX.Poll(form,options);
 		};
 	}
 	
@@ -695,9 +697,9 @@
 		A4J.AJAX._pollers[options.pollId]=undefined;
 		if((typeof(options.onsubmit) == 'function') && (options.onsubmit()==false)){
 			// Onsubmit disable current poll, start next interval.
-			A4J.AJAX.Poll(containerId,form,options);			
+			A4J.AJAX.Poll(form,options);			
 		} else {
-			A4J.AJAX.Submit(containerId,form,null,options);
+			A4J.AJAX.Submit(form,null,options);
 		}
 	},options.pollinterval);
 };
@@ -713,11 +715,11 @@
  * 
  * 
  */
-A4J.AJAX.Push =  function( containerId, form, options ) {
+A4J.AJAX.Push =  function(form, options) {
 	A4J.AJAX.StopPush(options.pushId);
 	options.onerror = function(){
 		// For error, re-submit request.
-		A4J.AJAX.Push(containerId,form,options);
+		A4J.AJAX.Push(form, options);
 	};
 	
 	options.onqueuerequestdrop = function() {
@@ -732,7 +734,7 @@
 		      		  if(request.status == 200){
 		      			if(request.getResponseHeader("Ajax-Push-Status")=="READY"){
 		      				A4J.AJAX.SetZeroRequestDelay(options);
-		      				A4J.AJAX.Submit(containerId,form||options.dummyForm,null,options);
+		      				A4J.AJAX.Submit(form||options.dummyForm,null,options);
 		      			}
 		      		  }
 		      		} catch(e){
@@ -742,10 +744,10 @@
 		      		request=null;
 					A4J.AJAX._pollers[options.pushId] = null;
 		      		// Re-send request.
-		      		A4J.AJAX.Push( containerId, form, options );
+		      		A4J.AJAX.Push(form, options);
 		      	}
 		}
-		A4J.AJAX.SendPush( request,options );
+		A4J.AJAX.SendPush(request, options);
 	},options.pushinterval);
 };
 
@@ -780,7 +782,7 @@
 }
 
 
-A4J.AJAX.SubmitForm =  function( containerId, form, options ) {
+A4J.AJAX.SubmitForm =  function(form, options) {
 	var opt = A4J.AJAX.CloneObject(options);
 	// Setup active control if form submitted by button.
 	if(A4J._formInput){
@@ -789,7 +791,7 @@
 		A4J._formInput = null;
 		opt.submitByForm=true;
 	}
-	A4J.AJAX.Submit(containerId,form,null,opt);
+	A4J.AJAX.Submit(form,null,opt);
 }
   
 /**
@@ -815,7 +817,7 @@
 	return domEvt;
 };
 
-A4J.AJAX.PrepareQuery = function(containerId, formId, domEvt, options) {
+A4J.AJAX.PrepareQuery = function(formId, domEvt, options) {
 	// Process listeners.
 	for(var li = 0; li < A4J.AJAX._listeners.length; li++){
   	  	var listener = A4J.AJAX._listeners[li];
@@ -840,7 +842,7 @@
     		return false;
     	};
     };
-    var tosend = new A4J.Query(containerId, form);
+    var tosend = new A4J.Query(options.containerId, form);
     tosend.appendFormControls(options.single, options.control);
     //appending options.control moved to appendFormControls
     //if(options.control){
@@ -906,9 +908,9 @@
 
 //Submit or put in queue request. It not full queues - framework perform waiting only one request to same queue, new events simple replace last.
 //If request for same queue already performed, replace with current parameters.
-A4J.AJAX.Submit =  function( containerId, formId, event , options ) {
+A4J.AJAX.Submit =  function(formId, event , options ) {
 	var domEvt = A4J.AJAX.CloneEvent(event);
-	var query = A4J.AJAX.PrepareQuery(containerId, formId, domEvt, options);
+	var query = A4J.AJAX.PrepareQuery(formId, domEvt, options);
     if (query) {
     	var queue = A4J.AJAX.EventQueue.getOrCreateQueue(options, formId);
     	
@@ -931,9 +933,9 @@
   // list of updated areas in response.
   // statusID - DOM id request status tags.
   // oncomplete - function for call after complete request.
-A4J.AJAX.SubmitRequest = function( containerId, formId, event, options ) {
+A4J.AJAX.SubmitRequest = function(formId, event, options ) {
 	var domEvt = A4J.AJAX.CloneEvent(event);
-	var query = A4J.AJAX.PrepareQuery(containerId, formId, domEvt, options);
+	var query = A4J.AJAX.PrepareQuery(formId, domEvt, options);
     if (query) {
     	A4J.AJAX.SubmitQuery(query, options, domEvt);
     }
@@ -1405,11 +1407,12 @@
   
 // Class for build query string.
 A4J.Query = function(containerId, form){ 
-	// For detect AJAX Request.
-	 this._query = {AJAXREQUEST : containerId};
+	 var containerIdOrDefault = containerId || A4J.AJAX.VIEW_ROOT_ID;
+	 // For detect AJAX Request.
+	 this._query = {AJAXREQUEST : containerIdOrDefault};
 	 this._oldSubmit = null ;	
 	 this._form = form;
-	 this._containerId = containerId;
+	 this._containerId = containerIdOrDefault;
 	 this._actionUrl = ( this._form.action)?this._form.action:this._form;
 	};
 




More information about the richfaces-svn-commits mailing list