[richfaces-svn-commits] JBoss Rich Faces SVN: r5861 - in trunk/sandbox/ui/progressBAR/src/main: java/org/richfaces/renderkit and 1 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Wed Feb 6 07:28:07 EST 2008


Author: andrei_exadel
Date: 2008-02-06 07:28:07 -0500 (Wed, 06 Feb 2008)
New Revision: 5861

Modified:
   trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/component/UIProgressBar.java
   trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java
   trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/js/progressBar.js
Log:
fix problems

Modified: trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/component/UIProgressBar.java
===================================================================
--- trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/component/UIProgressBar.java	2008-02-06 10:35:10 UTC (rev 5860)
+++ trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/component/UIProgressBar.java	2008-02-06 12:28:07 UTC (rev 5861)
@@ -21,7 +21,6 @@
 import org.ajax4jsf.context.AjaxContext;
 import org.ajax4jsf.context.AjaxContextImpl;
 import org.ajax4jsf.event.AjaxEvent;
-import org.ajax4jsf.javascript.JSFunctionDefinition;
 import org.ajax4jsf.javascript.JSLiteral;
 import org.ajax4jsf.renderkit.AjaxRendererUtils;
 import org.richfaces.renderkit.AbstractProgressBarRenderer;
@@ -39,10 +38,11 @@
     public static final String COMPONENT_TYPE = "org.richfaces.ProgressBar";
 
     public static final String COMPONENT_FAMILY = "org.richfaces.ProgressBar";
-
+    
     /** Request parameter name containing component state to render */
-    private static final String FORCE_STATE_PARAM = "forceState";
+    public static final String FORCE_PERCENT_PARAM = "forcePercent";
 
+ 
     /* (non-Javadoc)
      * @see org.ajax4jsf.component.AjaxActionComponent#broadcast(javax.faces.event.FacesEvent)
      */
@@ -59,11 +59,11 @@
 	    Number percent = getNumber(this.getAttributes().get("value"));
 	    Number maxValue = getNumber(this.getAttributes().get("maxValue"));
 	    Map params = request.getParameterMap();
-	    if (params.containsKey(FORCE_STATE_PARAM)) {
+	    if (params.containsKey(FORCE_PERCENT_PARAM)) {
 		ajaxContext.addComponentToAjaxRender(this);
-		String[] str = (String[]) params.get(FORCE_STATE_PARAM);
+		String[] str = (String[]) params.get(FORCE_PERCENT_PARAM);
 		for (String s : str) {
-		    this.getAttributes().put(FORCE_STATE_PARAM, s);
+		    this.getAttributes().put(FORCE_PERCENT_PARAM, s);
 		}
 	    } else if (percent.doubleValue() < maxValue.doubleValue()
 		    && params.containsKey("percent")) {
@@ -88,7 +88,7 @@
 
 	}
     }
-
+    
     /**
      * Returns ajax response data
      * 

Modified: trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java
===================================================================
--- trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java	2008-02-06 10:35:10 UTC (rev 5860)
+++ trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java	2008-02-06 12:28:07 UTC (rev 5861)
@@ -40,9 +40,6 @@
  */
 public class AbstractProgressBarRenderer extends TemplateEncoderRendererBase {
 
-    /** Request parameter name containing component state to render */
-    private static final String FORCE_STATE_PARAM = "forceState";
-
     /** Ajax function performing polling */
     private static final String AJAX_POLL_FUNCTION = "A4J.AJAX.Poll";
 
@@ -74,9 +71,9 @@
 	} else if ("complete".equals(state)) {
 	    encodeCompletedState(context, component);
 	}
-	component.getAttributes().remove(FORCE_STATE_PARAM);
+	component.getAttributes().remove(UIProgressBar.FORCE_PERCENT_PARAM);
     }
-
+    
     /**
      * Gets state forced from javascript
      * 
@@ -84,10 +81,32 @@
      * @return
      */
     public String getForcedState(UIComponent component) {
-	if (component.getAttributes().containsKey(FORCE_STATE_PARAM)) {
-	    return (String) component.getAttributes().get(FORCE_STATE_PARAM);
+	String forcedState = null;
+	if (component.getAttributes().containsKey(UIProgressBar.FORCE_PERCENT_PARAM)) {
+	    ComponentVariables variables = ComponentsVariableResolver
+		    .getVariables(this, component);
+	    Number maxValue = getNumber(component.getAttributes().get(
+		    "maxValue"));
+	    Number minValue = getNumber(component.getAttributes().get(
+		    "minValue"));
+	    String percent = (String) component.getAttributes().get(
+		    UIProgressBar.FORCE_PERCENT_PARAM);
+	    Number p = null;
+	    try {
+		p = getNumber(percent);
+		if (p.doubleValue() < minValue.doubleValue()) {
+		    forcedState = "initial";
+		} else if (p.doubleValue() > maxValue.doubleValue()) {
+		    forcedState = "complete";
+		} else {
+		    forcedState = "progress";
+		}
+		variables.setVariable("percent", p);
+	    } catch (Exception e) {
+		e.getMessage();
+	    }
 	}
-	return null;
+	return forcedState;
     }
 
     /**
@@ -199,11 +218,11 @@
      * @param component
      * @throws IOException
      */
-    public void encodeInitialScript(FacesContext context, UIComponent component)
+    public void encodeInitialScript(FacesContext context, UIComponent component, String state)
 	    throws IOException {
 	ResponseWriter writer = context.getResponseWriter();
 	UIProgressBar progressBar = (UIProgressBar) component;
-
+	ComponentVariables variables = ComponentsVariableResolver.getVariables(this, component);
 	writer.startElement(HTML.SPAN_ELEM, component);
 	writer.writeAttribute(HTML.style_ATTRIBUTE, "display: none;", null);
 	writer.startElement(HTML.SCRIPT_ELEM, component);
@@ -217,7 +236,9 @@
 	String mode = (String) component.getAttributes().get("mode");
 	Integer minValue = (Integer) component.getAttributes().get("minValue");
 	Integer maxValue = (Integer) component.getAttributes().get("maxValue");
-
+	Number  value = (Number)variables.getVariable("percent");
+	StringBuffer markup = getMarkup(context, component); 
+	
 	script.append("new ProgressBar('")
 		.append(clientId).append("','")    // id
 		.append(containerId).append("','") // containerId
@@ -227,6 +248,8 @@
 		.append(maxValue).append(",");     // max value
 	script.append(getContext(component));      // context
 	script.append(",");
+	script.append(markup != null ? new JSLiteral(markup.toString()) : JSReference.NULL); //markup
+	script.append(",");
 	script.append(ScriptUtils.toScript(buildAjaxOptions(clientId, // options
 		progressBar, context)));
 	String progressVar = (String) component.getAttributes().get(  
@@ -234,11 +257,13 @@
 	if (progressVar != null) {
 	    script.append(",'");
 	    script.append(progressVar);             // progress var
-	    script.append("'");
+	    script.append("','");
 	} else {
-	    script.append(",null");
+	    script.append(",null,'");
 	}
-
+	script.append(state);
+	script.append("',");
+	script.append(value.toString());
 	script.append(");\n");
 	writer.write(script.toString());
 
@@ -303,7 +328,7 @@
 	if (initial != null) {
 	    renderChild(context, initial);
 	}
-	encodeInitialScript(context, component);
+	encodeInitialScript(context, component,"initial");
 	if (isAjaxMode(component)) {
 	    encodePollScript(context, component);
 	}
@@ -333,7 +358,7 @@
 	getUtils().writeAttribute(writer, "id", clientId);
 	getUtils().writeAttribute(writer, "style",
 		variables.getVariable("style"));
-	encodeInitialScript(context, component);
+	encodeInitialScript(context, component,"progress");
 	encodeProgressBar(context, component);
 	encodeLabelScript(context, component);
 	writer.endElement("div");
@@ -471,7 +496,7 @@
 	if (completed != null) {
 	    renderChild(context, completed);
 	}
-	encodeInitialScript(context, component);
+	encodeInitialScript(context, component,"completed");
 	if (isAjax) {
 	    writer.startElement(HTML.SPAN_ELEM, component);
 		writer.writeAttribute(HTML.style_ATTRIBUTE, "display: none;", null);

Modified: trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/js/progressBar.js
===================================================================
--- trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/js/progressBar.js	2008-02-06 10:35:10 UTC (rev 5860)
+++ trunk/sandbox/ui/progressBAR/src/main/resources/org/richfaces/renderkit/html/js/progressBar.js	2008-02-06 12:28:07 UTC (rev 5861)
@@ -1,17 +1,19 @@
 ProgressBar = {};
 ProgressBar = Class.create();
 Object.extend(ProgressBar.prototype, {
-    initialize: function(id, containerId, formId, mode, minValue, maxValue, context, options, progressVar) {
+    initialize: function(id, containerId, formId, mode, minValue, maxValue, context, markup, options, progressVar, state, value) {
 		this.id = id;
-		$(this.id).component = this;
-		
+				
 		this.containerId = containerId;
 		this.formId = formId;
 		this.mode = mode;
+		this.state = state;
 		this.minValue = minValue;
 		this.maxValue = maxValue;
+		this.value = value;
 	
 		this.context = context;
+		this.markup = markup;
 		this.options = options || {};
 		
 		this.options.onbeforedomupdate = function(request, event, data) {
@@ -19,23 +21,23 @@
 		}.bind(this);
 		
 		this.progressVar = progressVar;
+		$(this.id).component = this;
     },
 
 	getValue: function () {
-		var d = $(this.id + ":upload");
-		if (d != null) {
-			var w = d.style.width; 
-			if (w) {
-				return w.substring(0,w.length - 1);		
-			}
-		}
-	return null;
+		return this.value;
 	},
 	onComplete: function (data) {
 	  	if (!$(this.id)) { return; } 
 		if (data) {
-			this.updateComponent(data);
-			this.renderLabel(data['markup'], data['context']);
+			this.value = data['percent'];
+			if (this.state == "progress") {
+				this.updateComponent(data);
+				this.renderLabel(data['markup'], data['context']);
+			} else if (this.state == "initial" && this.value == this.getMinValue()) {
+				this.state = "progress";
+				this.forceState(this.value, function () { this.poll() }.bind(this));
+			}
 			this.poll();
 		}
 		
@@ -89,14 +91,14 @@
 		if (!context) { context = {}; }
 			context['minValue'] = this.minValue;
 			context['maxValue'] = this.maxValue;
-			context['value'] = (this.value ? this.value : this.getValue());
+			context['value'] = (this.value == 0 ? "0" : this.value);
 			if (this.progressVar) {
 				context[this.progressVar] = context['value'];
 			}
 		return context;
 	},
 	renderLabel: function (markup, context) {
-		if (!markup) {
+		if (!markup || this.state != "progress") {
 			return;
 		}
 		if (!context) {
@@ -114,9 +116,11 @@
 		return placeholders;
 	},
 	setLabel: function (str) {
+	if (this.state != "progress") { return; }
 		var lbl = this.interpolate(str, this.getContext());
 		if (lbl)
 			$(this.id + ":remain").innerHTML = $(this.id + ":complete").innerHTML = lbl;
+	this.markup = null;
 	},
 	getMode: function () {
 		return this.mode;
@@ -131,33 +135,38 @@
 		return (this.getMode() == "ajax");
 	}, 
 	setValue: function (val) {
+		this.value = val;
+		var p = val;
 		val = "" + val;
-		var p = val;
 		if (val != null) {
 			if (val.indexOf("%") < 0)
 				val = val + "%";
 		}
 		if ( parseFloat(p) <  parseFloat(this.getMinValue())) {
 			if (!this.isAjaxMode()) { 
-				this.forceState("initial",null);
+				this.forceState(p, null);
 				return;
 			}
 		} else if ( parseFloat(p) > parseFloat(this.getMaxValue()))  {
 			if (!this.isAjaxMode()) { 
-				this.forceState("complete",null);
+				this.forceState(p, null);
 				return;
 			} 
 		}
 		
+		if (this.markup) {
+			this.renderLabel(this.markup, this.getContext());
+		} else {
+			this.setLabel("{value}%");
+		}
+	
 		d = $(this.id + ":upload");
 		if (d != null) d.style.width = val;
 	
 	},
 	enable: function (ev) {
 		if (!this.isAjaxMode()) {
-			this.forceState("progress", function() { 
-				this.setValue(0); 
-			}.bind(this));
+			this.forceState("0", null);
 		}else {
 			this.disable();
 			this.poll();			
@@ -169,11 +178,11 @@
 	finish: function () {
 		//this.switchMode("completed");
 	},
-	forceState: function (state, oncomplete) {
+	forceState: function (percent, oncomplete) {
 		var options = {};
 		options['parameters'] = {};
 		options['parameters'][this.id] = this.id;
-		options['parameters']['forceState'] = state;
+		options['parameters']['forcePercent'] = percent;
 		options['actionUrl'] = this.options.actionUrl;
 		if (oncomplete) {
 			options['oncomplete'] = oncomplete;




More information about the richfaces-svn-commits mailing list