Author: nbelaevski
Date: 2010-11-26 09:35:45 -0500 (Fri, 26 Nov 2010)
New Revision: 20177
Added:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarState.java
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarStateEncoder.java
Modified:
trunk/examples/output-demo/src/main/java/org/richfaces/ProgressBarBean.java
trunk/examples/output-demo/src/main/webapp/examples/progressbar.xhtml
trunk/examples/output-demo/src/main/webapp/templates/template.xhtml
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RendererBase.java
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractProgressBar.java
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarBaseRenderer.java
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/progressBar.ecss
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/progressBar.js
trunk/ui/output/ui/src/main/templates/progressBar.template.xml
Log:
https://jira.jboss.org/browse/RFPL-934
Modified: trunk/examples/output-demo/src/main/java/org/richfaces/ProgressBarBean.java
===================================================================
--- trunk/examples/output-demo/src/main/java/org/richfaces/ProgressBarBean.java 2010-11-26
14:26:49 UTC (rev 20176)
+++ trunk/examples/output-demo/src/main/java/org/richfaces/ProgressBarBean.java 2010-11-26
14:35:45 UTC (rev 20177)
@@ -3,8 +3,10 @@
*/
package org.richfaces;
+import java.io.Serializable;
+import java.text.DateFormat;
import java.util.Date;
-
+
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
@@ -14,37 +16,22 @@
*/
@ManagedBean
@ViewScoped
-public class ProgressBarBean {
+public class ProgressBarBean implements Serializable {
+
+ private static final long serialVersionUID = -446286889238296278L;
+
+ private int minValue = 0;
+
+ private int maxValue = 100;
+
+ private int value = 50;
+
+ private String label = "'label' attribute";
+
+ private boolean childrenRendered = false;
+
+ private boolean enabled = false;
- private boolean buttonRendered = true;
- private boolean enabled=false;
- private Long startTime;
-
- public String startProcess() {
- setEnabled(true);
- setButtonRendered(false);
- setStartTime(new Date().getTime());
- return null;
- }
-
- public Long getCurrentValue(){
- if (isEnabled()) {
- Long current = (new Date().getTime() - startTime)/1000;
- if (current>100){
- setButtonRendered(true);
- } else if (current.equals(0)) {
- return new Long(1);
- }
- return (new Date().getTime() - startTime)/1000;
- }
- if (startTime == null) {
- return Long.valueOf(-1);
- } else {
- return Long.valueOf(101);
- }
-
- }
-
public boolean isEnabled() {
return enabled;
}
@@ -53,19 +40,55 @@
this.enabled = enabled;
}
- public Long getStartTime() {
- return startTime;
+ public int getMinValue() {
+ return minValue;
}
-
- public void setStartTime(Long startTime) {
- this.startTime = startTime;
+
+ public void setMinValue(int minValue) {
+ this.minValue = minValue;
}
-
- public boolean isButtonRendered() {
- return buttonRendered;
+
+ public int getMaxValue() {
+ return maxValue;
}
-
- public void setButtonRendered(boolean buttonRendered) {
- this.buttonRendered = buttonRendered;
+
+ public void setMaxValue(int maxValue) {
+ this.maxValue = maxValue;
}
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(int value) {
+ this.value = value;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public boolean isChildrenRendered() {
+ return childrenRendered;
+ }
+
+ public void setChildrenRendered(boolean childrenRendered) {
+ this.childrenRendered = childrenRendered;
+ }
+
+ public void decreaseValueByFive() {
+ value -= 5;
+ }
+
+ public void increaseValueByFive() {
+ value += 5;
+ }
+
+ public String getCurrentTimeAsString() {
+ return DateFormat.getTimeInstance().format(new Date());
+ }
}
\ No newline at end of file
Modified: trunk/examples/output-demo/src/main/webapp/examples/progressbar.xhtml
===================================================================
--- trunk/examples/output-demo/src/main/webapp/examples/progressbar.xhtml 2010-11-26
14:26:49 UTC (rev 20176)
+++ trunk/examples/output-demo/src/main/webapp/examples/progressbar.xhtml 2010-11-26
14:35:45 UTC (rev 20177)
@@ -1,79 +1,105 @@
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
-
xmlns:h="http://java.sun.com/jsf/html"
-
xmlns:f="http://java.sun.com/jsf/core"
-
xmlns:ui="http://java.sun.com/jsf/facelets"
-
xmlns:a4j="http://richfaces.org/a4j"
-
xmlns:rich="http://richfaces.org/output"
template="/templates/template.xhtml">
-
- <ui:define name="body">
- <script>
-//<![CDATA[
- var counter = 1;
- var intervalID;
- function updateProgress(i) {
- RichFaces.$('form2:progressBar').setValue(counter*5);
- if ((counter++)>20){
- clearInterval(intervalID);
- document.getElementById('button').disabled=false;
- }
- }
-
- function startProgress(){
- counter=1;
- document.getElementById('button').disabled=true;
- RichFaces.$('form2:progressBar').enable();
- RichFaces.$('form2:progressBar').setValue(1);
- intervalID = setInterval(updateProgress,5000);
- }
-//]]>
- </script>
- <h:form id="form">
- Ajax mode:
- <rich:progressBar mode="ajax"
value="#{progressBarBean.currentValue}"
- interval="2000"
- enabled="#{progressBarBean.enabled}" minValue="-1"
maxValue="100"
- reRenderAfterComplete="progressPanel">
- <f:facet name="initial">
- <br />
- <h:outputText value="Process doesn't started yet"
/>
- <a4j:commandButton
action="#{progressBarBean.startProcess}"
- value="Start Process"
- render="form"
- style="margin: 9px 0px 5px;" />
- </f:facet>
- <f:facet name="complete">
- <br />
- <h:outputText value="Process Done" />
- <a4j:commandButton
action="#{progressBarBean.startProcess}"
- value="Restart Process" execute="@form"
- rendered="#{progressBarBean.buttonRendered}"
- style="margin: 9px 0px 5px;" />
- </f:facet>
- <h:outputText value="#{progressBarBean.currentValue}
%"/>
- </rich:progressBar>
- <h:panelGroup id="progressPanel">
- <h:outputText value="#{progressBarBean.currentValue}"/>
- </h:panelGroup>
- </h:form>
-
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:rich="http://richfaces.org/output"
+ template="/templates/template.xhtml">
+ <ui:define name="body">
+ <h:form>
+ Min value: <h:selectOneMenu value="#{progressBarBean.minValue}"
onchange="submit()">
+ <f:selectItem itemLabel="0" itemValue="0" />
+ <f:selectItem itemLabel="-50" itemValue="-50" />
+ </h:selectOneMenu>
- Client mode:
+ <br />
+
+ Value: <h:selectOneMenu value="#{progressBarBean.value}"
onchange="submit()">
+ <f:selectItem itemLabel="-25" itemValue="-25" />
+ <f:selectItem itemLabel="0" itemValue="0" />
+ <f:selectItem itemLabel="25" itemValue="25" />
+ <f:selectItem itemLabel="50" itemValue="50" />
+ <f:selectItem itemLabel="100" itemValue="100" />
+ <f:selectItem itemLabel="150" itemValue="150" />
+ </h:selectOneMenu>
+
+ <br />
+
+ Max value: <h:selectOneMenu value="#{progressBarBean.maxValue}"
onchange="submit()">
+ <f:selectItem itemLabel="50" itemValue="50" />
+ <f:selectItem itemLabel="100" itemValue="100" />
+ </h:selectOneMenu>
+
+ <br />
+
+ Label: <h:inputText value="#{progressBarBean.label}"
onchange="submit()" />
+
+ <br />
+
+ Children rendered: <h:selectBooleanCheckbox
value="#{progressBarBean.childrenRendered}" onclick="submit()" />
+
+ <br />
+
+ Enabled: <h:selectBooleanCheckbox value="#{progressBarBean.enabled}"
onclick="submit()" />
+ </h:form>
+
+ Client mode:
+ <h:form id="clientPBForm">
+
+ <rich:progressBar mode="client" id="progressBar"
value="#{progressBarBean.value}"
+ maxValue="#{progressBarBean.maxValue}"
minValue="#{progressBarBean.minValue}"
label="#{progressBarBean.label}">
- <h:form id="form2">
- <rich:progressBar mode="client" id="progressBar">
- <f:facet name="initial">
- <h:outputText value="Process doesn't started yet"/>
- </f:facet>
- <f:facet name="complete">
- <h:outputText value="Process Done"/>
- </f:facet>
- </rich:progressBar>
- <button type="button" onclick="startProgress();"
style="margin: 9px 0px 5px;" id="button">Start
Progress</button>
- </h:form>
+ <h:outputText value="child + "
rendered="#{progressBarBean.childrenRendered}" />
+
+ <f:facet name="initial">
+ <h:outputText value="In initial state" />
+ </f:facet>
+
+ <f:facet name="finish">
+ <h:outputText value="Finished progress" />
+ </f:facet>
+
+ </rich:progressBar>
+
+ Set value via CS-API: <h:inputText size="3"
onchange="RichFaces.$('clientPBForm:progressBar').setValue(this.value)"
/>
+
+ </h:form>
+
+
+ <h:form id="ajaxPBForm">
+ Ajax mode:
+ <rich:progressBar id="progressBar" mode="ajax"
interval="2000" value="#{progressBarBean.value}"
+ maxValue="#{progressBarBean.maxValue}"
minValue="#{progressBarBean.minValue}"
+ label="#{progressBarBean.value} % ~ #{progressBarBean.currentTimeAsString}"
reRenderAfterComplete="progressPanel"
+ onfinish="alert('\'finish\' event handler: ' +
this.tagName)"
+ enabled="#{progressBarBean.enabled}">
+ <h:outputText value="child + "
rendered="#{progressBarBean.childrenRendered}" />
+
+ <f:facet name="initial">
+ <h:outputText value="initial ~ #{progressBarBean.currentTimeAsString}"
/>
+ </f:facet>
+
+ <f:facet name="finish">
+ <h:outputText value="finish ~ #{progressBarBean.currentTimeAsString}"
/>
+ </f:facet>
+ </rich:progressBar>
+
+ Current value: <h:panelGroup
id="currentValue">#{progressBarBean.value}</h:panelGroup>
+ <br />
+ <a4j:commandLink value="-5"
action="#{progressBarBean.decreaseValueByFive}" render="currentValue"
/>
+
+ <h:outputText value=" / " />
+
+ <a4j:commandLink value="+5"
action="#{progressBarBean.increaseValueByFive}" render="currentValue"
/>
+
+ <h:outputText value=" / " />
+
+ <a4j:commandLink value="re-render progress bar"
render="progressBar" />
+ </h:form>
</ui:define>
</ui:composition>
-
+
Modified: trunk/examples/output-demo/src/main/webapp/templates/template.xhtml
===================================================================
--- trunk/examples/output-demo/src/main/webapp/templates/template.xhtml 2010-11-26
14:26:49 UTC (rev 20176)
+++ trunk/examples/output-demo/src/main/webapp/templates/template.xhtml 2010-11-26
14:35:45 UTC (rev 20177)
@@ -10,6 +10,7 @@
</title>
<meta http-equiv="content-type" content="text/xhtml;
charset=UTF-8" />
+ <h:outputScript library="javax.faces" name="jsf.js"
target="head" />
</h:head>
<h:body>
Modified: trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RendererBase.java
===================================================================
--- trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RendererBase.java 2010-11-26
14:26:49 UTC (rev 20176)
+++ trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RendererBase.java 2010-11-26
14:35:45 UTC (rev 20177)
@@ -151,8 +151,6 @@
component.getClass().getName()));
}
- preEncodeBegin(context, component);
-
if (component.isRendered()) {
ResponseWriter writer = context.getResponseWriter();
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractProgressBar.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractProgressBar.java 2010-11-26
14:26:49 UTC (rev 20176)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractProgressBar.java 2010-11-26
14:35:45 UTC (rev 20177)
@@ -27,28 +27,25 @@
package org.richfaces.component;
-import java.util.HashMap;
+import java.io.IOException;
import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
+import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
+import javax.faces.component.visit.VisitCallback;
+import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitResult;
import javax.faces.context.FacesContext;
-import javax.faces.context.PartialViewContext;
-import javax.faces.event.AbortProcessingException;
-import javax.faces.event.FacesEvent;
-import org.ajax4jsf.javascript.JSLiteral;
-import org.ajax4jsf.javascript.ScriptUtils;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.EventName;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.cdk.annotations.Tag;
import org.richfaces.cdk.annotations.TagType;
-import org.richfaces.renderkit.HtmlConstants;
-import org.richfaces.renderkit.html.ProgressBarBaseRenderer;
-import org.richfaces.renderkit.util.CoreAjaxRendererUtils;
+import org.richfaces.context.ExtendedVisitContext;
+import org.richfaces.context.ExtendedVisitContextMode;
+import org.richfaces.renderkit.MetaComponentRenderer;
/**
* Class provides base component class for progress bar
@@ -57,46 +54,16 @@
*
*/
@JsfComponent(tag = @Tag(type = TagType.Facelets), renderer = @JsfRenderer(type =
"org.richfaces.ProgressBarRenderer"))
-public abstract class AbstractProgressBar extends UIComponentBase{
+public abstract class AbstractProgressBar extends UIComponentBase implements
MetaComponentResolver, MetaComponentEncoder {
- /** Component type */
+ /** Component type */
public static final String COMPONENT_TYPE = "org.richfaces.ProgressBar";
- /** Component family */
+ /** Component family */
public static final String COMPONENT_FAMILY = "org.richfaces.ProgressBar";
- /** Request parameter name containing component state to render */
- public static final String FORCE_PERCENT_PARAM = "forcePercent";
+ public static final String STATE_META_COMPONENT_ID = "state";
- /** Percent param name */
- private static final String PERCENT_PARAM = "percent";
-
- /** Max value attribute name */
- private static final String MAXVALUE = "maxValue";
-
- /** Min value attribute name */
- private static final String MINVALUE = "minValue";
-
- /** Enabled attribute name */
- private static final String ENABLED = "enabled";
-
- /** Enabled attribute name */
- private static final String INTERVAL = "interval";
-
- /** Markup data key */
- private static final String MARKUP = "markup";
-
- /** Complete class attribute name */
- private static final String COMPLETECLASS = "completeClass";
-
- /** Remain class attribute name */
- private static final String REMAINCLASS = "remainClass";
-
- /** Style class attribute name */
- private static final String STYLECLASS = "styleClass";
-
- /** Context key */
- private static final String CONTEXT = "context";
@Attribute(events = @EventName("click"))
public abstract String getOnclick();
@@ -117,17 +84,18 @@
@Attribute(events = @EventName("mouseout"))
public abstract String getOnmouseout();
-
- @Attribute(events = @EventName("submit"))
- public abstract String getOnsubmit();
-
-
+
+ @Attribute(events = @EventName("begin"))
+ public abstract String getOnbegin();
+
@Attribute
public abstract String getLabel();
-
+
@Attribute
public abstract Object getData();
+
public abstract void setData(Object data);
+
@Attribute(defaultValue = "1000")
public abstract int getInterval();
@@ -139,206 +107,96 @@
@Attribute(events = @EventName("complete"))
public abstract String getOncomplete();
-
+
+ @Attribute(events = @EventName("finish"))
+ public abstract String getOnfinish();
+
@Attribute
- public abstract String getCompleteClass();
-
- @Attribute
- public abstract String getFinishClass();
-
- @Attribute
public abstract String getInitialClass();
-
+
@Attribute
- public abstract String getRemainClass();
-
+ public abstract String getRemainingClass();
+
@Attribute
- public abstract String getFocus();
-
+ public abstract String getProgressClass();
+
@Attribute
- public abstract String getReRenderAfterComplete();
-
+ public abstract String getFinishClass();
+
+ @Attribute(defaultValue = "SwitchType.DEFAULT")
+ public abstract SwitchType getMode();
+
@Attribute
- public abstract String getMode();
-
- @Attribute
public abstract int getMaxValue();
-
+
@Attribute
public abstract int getMinValue();
-
+
@Attribute
public abstract Object getValue();
-
- @Attribute
- public abstract Object getParameters();
-
-
- /**
- * Method performs broadcasting of jsf events to progress bar component
- *
- * @param event -
- * Faces Event instance
- */
- public void broadcast(FacesEvent event) throws AbortProcessingException {
- FacesContext facesContext = FacesContext.getCurrentInstance();
- Map<String, String> params =
facesContext.getExternalContext().getRequestParameterMap();
- String clientId = this.getClientId(facesContext);
+ public void encodeMetaComponent(FacesContext context, String metaComponentId) throws
IOException {
+ ((MetaComponentRenderer) getRenderer(context)).encodeMetaComponent(context, this,
metaComponentId);
+ }
- if (!params.containsKey(clientId)) {
- return;
+ @Override
+ public boolean visitTree(VisitContext context, VisitCallback callback) {
+ if (!isVisitable(context)) {
+ return false;
}
- if (!params.containsKey(FORCE_PERCENT_PARAM)
- && params.containsKey(PERCENT_PARAM)) {
- Number value = NumberUtils.getNumber(this.getAttributes().get(
- HtmlConstants.VALUE_ATTRIBUTE));
- PartialViewContext pvc =
FacesContext.getCurrentInstance().getPartialViewContext();
- pvc.getRenderIds().remove(
- this.getClientId());
- this.setData(getResponseData(value, facesContext));
- } else if (params.containsKey(FORCE_PERCENT_PARAM)) {
- PartialViewContext pvc =
FacesContext.getCurrentInstance().getPartialViewContext();
- pvc.getRenderIds().add(this.getClientId());
- String forcedState = params.get(FORCE_PERCENT_PARAM);
- if ("completeState".equals(forcedState)) {
- Object reRender =
this.getAttributes().get("reRenderAfterComplete");
- Set<String> ajaxRegions =
CoreAjaxRendererUtils.asIdsSet(reRender);
- if (ajaxRegions != null) {
- for (Iterator<String> iter = ajaxRegions.iterator();
iter.hasNext();) {
- String id = iter.next();
- pvc.getExecuteIds().add(id);
- pvc.getRenderIds().add(id);
+ FacesContext facesContext = context.getFacesContext();
+ pushComponentToEL(facesContext, null);
+
+ try {
+ VisitResult result = context.invokeVisitCallback(this, callback);
+
+ if (result == VisitResult.COMPLETE) {
+ return true;
+ }
+
+ if (result == VisitResult.ACCEPT) {
+ if (context instanceof ExtendedVisitContext) {
+ ExtendedVisitContext extendedVisitContext = (ExtendedVisitContext)
context;
+ if (extendedVisitContext.getVisitMode() ==
ExtendedVisitContextMode.RENDER) {
+
+ result =
extendedVisitContext.invokeMetaComponentVisitCallback(this, callback,
STATE_META_COMPONENT_ID);
+ if (result == VisitResult.COMPLETE) {
+ return true;
+ }
}
}
}
- }
- }
-
- /**
- * Returns ajax response data
- *
- * @param uiComponent
- * @param percent
- * @return
- */
- private Map<Object, Object> getResponseData(Number value,
- FacesContext facesContext) {
+
+ if (result == VisitResult.ACCEPT) {
+ Iterator<UIComponent> kids = this.getFacetsAndChildren();
- ProgressBarBaseRenderer renderer = (ProgressBarBaseRenderer) this
- .getRenderer(facesContext);
+ while(kids.hasNext()) {
+ boolean done = kids.next().visitTree(context, callback);
- Map<Object, Object> map = new HashMap<Object, Object>();
- map.put(HtmlConstants.VALUE_ATTRIBUTE, value);
- map.put(INTERVAL, this.getInterval());
-
- if (this.getAttributes().get(HtmlConstants.STYLE_ATTRIBUTE) != null) {
- map.put(HtmlConstants.STYLE_ATTRIBUTE, this.getAttributes()
- .get(HtmlConstants.STYLE_ATTRIBUTE));
+ if (done) {
+ return true;
+ }
+ }
+ }
+ } finally {
+ popComponentFromEL(facesContext);
}
- map.put(ENABLED, (Boolean) this.getAttributes().get(ENABLED));
-
- if (!isSimple(renderer)) {
- map.put(MARKUP, getMarkup(facesContext, renderer));
- map.put(CONTEXT, getContext(renderer, value));
- }
-
- addStyles2Responce(map, COMPLETECLASS, this.getAttributes().get(
- COMPLETECLASS));
- addStyles2Responce(map, REMAINCLASS, this.getAttributes().get(
- REMAINCLASS));
- addStyles2Responce(map, STYLECLASS, this.getAttributes().get(
- STYLECLASS));
- return map;
-
+ return false;
}
- /**
- * Returns context for macrosubstitution
- *
- * @param renderer
- * @param percent
- * @return
- */
- private JSLiteral getContext(ProgressBarBaseRenderer renderer,
- Number percent) {
- StringBuffer buffer = new StringBuffer("{");
- buffer.append("\"value\":");
- buffer.append(ScriptUtils.toScript(percent.toString())).append(",");
- buffer.append("\"minValue\":");
- buffer.append(
- ScriptUtils.toScript(this.getAttributes().get(MINVALUE)
- .toString())).append(",");
- buffer.append("\"maxValue\":");
- buffer.append(ScriptUtils.toScript(this.getAttributes().get(MAXVALUE)
- .toString()));
+ public String resolveClientId(FacesContext facesContext, UIComponent
contextComponent, String metaComponentId) {
- String parameters = handleParameters(renderer.getParameters(this));
- if (parameters != null) {
- buffer.append(",");
- buffer.append(parameters);
+ if (STATE_META_COMPONENT_ID.equals(metaComponentId)) {
+ return contextComponent.getClientId(facesContext) +
MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR + metaComponentId;
}
- buffer.append("}");
- return new JSLiteral(buffer.toString());
- }
- private String handleParameters(String str){
- if (str != null && str.length() > 0) {
- StringBuilder s = new StringBuilder();
- while(str.indexOf(":") != -1){
- String a = str.substring(0, str.indexOf(":"));
- str = str.substring(str.indexOf(":") );
- s.append("\"");
- s.append(a);
- s.append("\"");
- if (str.indexOf(",") != -1) {
- String b = str.substring(0, str.indexOf(",") +1);
- str = str.substring(str.indexOf(",") +1 );
- s.append(b);
- } else{
- s.append(str);
- return s.toString();
- }
- }
- }
return null;
}
-
- /**
- * Return true if markup is simple
- *
- * @return
- */
- private boolean isSimple(ProgressBarBaseRenderer renderer) {
- return renderer.isSimpleMarkup(this);
- }
- /**
- * Returns label markup
- *
- * @param context
- * @param renderer
- * @return
- */
- private String getMarkup(FacesContext context,
- ProgressBarBaseRenderer renderer) {
- return renderer.getMarkup(context, this).toString();
+ public String substituteUnresolvedClientId(FacesContext facesContext, UIComponent
contextComponent,
+ String metaComponentId) {
+ return null;
}
-
- /**
- * Add component classes to ajax response
- *
- * @param buffer
- * @param attr
- * @param newValue
- */
- private void addStyles2Responce(Map<Object, Object> map, String key,
- Object className) {
- if (className != null) {
- map.put(key, className);
- }
- }
-
}
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarBaseRenderer.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarBaseRenderer.java 2010-11-26
14:26:49 UTC (rev 20176)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarBaseRenderer.java 2010-11-26
14:35:45 UTC (rev 20177)
@@ -27,370 +27,139 @@
package org.richfaces.renderkit.html;
-import static org.richfaces.renderkit.RenderKitUtils.addToScriptHash;
-
import java.io.IOException;
-import java.io.StringWriter;
-import java.util.HashMap;
import java.util.Map;
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
+import javax.faces.context.PartialResponseWriter;
import javax.faces.context.PartialViewContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.event.ActionEvent;
-import org.ajax4jsf.javascript.JSLiteral;
-import org.ajax4jsf.javascript.ScriptUtils;
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.JSReference;
import org.richfaces.component.AbstractProgressBar;
+import org.richfaces.component.MetaComponentResolver;
import org.richfaces.component.NumberUtils;
-import org.richfaces.log.Logger;
-import org.richfaces.log.RichfacesLogger;
+import org.richfaces.component.SwitchType;
+import org.richfaces.renderkit.AjaxEventOptions;
+import org.richfaces.renderkit.MetaComponentRenderer;
import org.richfaces.renderkit.RendererBase;
-import org.richfaces.renderkit.util.RendererUtils;
+import org.richfaces.renderkit.util.AjaxRendererUtils;
/**
* Abstract progress bar renderer
*
- * @author "Andrey Markavtsov"
+ * @author Nick Belaevski
*
*/
@ResourceDependencies( {
@ResourceDependency(library = "org.richfaces", name =
"ajax.reslib"),
@ResourceDependency(library = "org.richfaces", name =
"base-component.reslib"),
+ @ResourceDependency(name = "richfaces-event.js"),
@ResourceDependency(library = "org.richfaces", name =
"progressBar.js"),
@ResourceDependency(library = "org.richfaces", name =
"progressBar.ecss")
})
-public class ProgressBarBaseRenderer extends RendererBase {
+public class ProgressBarBaseRenderer extends RendererBase implements
MetaComponentRenderer {
- private static final String INITIAL_FACET = "initial";
- private static final String COMPLETE_FACET = "complete";
- private static final Logger LOG = RichfacesLogger.APPLICATION.getLogger();
+ private static final JSReference BEFORE_UPDATE_HANDLER = new
JSReference("beforeUpdateHandler");
+
+ private static final JSReference AFTER_UPDATE_HANDLER = new
JSReference("afterUpdateHandler");
+
+ private static final ProgressBarStateEncoder FULL_ENCODER = new
ProgressBarStateEncoder(false);
-
+ private static final ProgressBarStateEncoder PARTIAL_ENCODER = new
ProgressBarStateEncoder(true);
+
@Override
protected void doDecode(FacesContext context, UIComponent component) {
super.doDecode(context, component);
- if (component.isRendered()) {
- new ActionEvent(component).queue();
+
+ Map<String, String> params =
context.getExternalContext().getRequestParameterMap();
+ if (params.get(component.getClientId(context)) != null) {
PartialViewContext pvc = context.getPartialViewContext();
- pvc.getRenderIds().add(component.getClientId(context));
+ pvc.getRenderIds().add(component.getClientId(context) +
+ MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR +
AbstractProgressBar.STATE_META_COMPONENT_ID);
}
-
}
- /*
- * (non-Javadoc)
- *
- * @see
org.richfaces.renderkit.TemplateEncoderRendererBase#encodeChildren(javax.faces.context.FacesContext,
- * javax.faces.component.UIComponent)
- */
- @Override
- public void encodeChildren(FacesContext context, UIComponent component) throws
IOException {
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.ajax4jsf.renderkit.RendererBase#doEncodeChildren(javax.faces.context.ResponseWriter,
- * javax.faces.context.FacesContext, javax.faces.component.UIComponent)
- */
- @Override
- public void doEncodeChildren(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
-
- }
-
- public final boolean getRendersChildren() {
- return true;
- }
-
/**
- * Gets state forced from javascript
- *
- * @param component
- * @return
- */
- public String getForcedState(FacesContext context, UIComponent component) {
- String forcedState = null;
- Map<String, String> params = context.getExternalContext()
- .getRequestParameterMap();
- if (params.containsKey(AbstractProgressBar.FORCE_PERCENT_PARAM)) {
- forcedState = params.get(AbstractProgressBar.FORCE_PERCENT_PARAM);
- }
- return forcedState;
- }
-
- /**
- * Renderes label markup
- *
- * @param context
- * @param component
- * @return
- */
- public StringBuffer getMarkup(FacesContext context, UIComponent component) {
- StringBuffer result = new StringBuffer();
- try {
- result = new StringBuffer(getMarkupBody(context, component,
hasChildren(component)));
-
- } catch (Exception e) {
- LOG.error("Error occurred during rendering of progress bar label. It
switched to empty string", e);
- }
-
- return result;
-
- }
-
-
-
- protected String getMarkupBody(FacesContext context, UIComponent component, boolean
children) throws IOException {
- ResponseWriter writer = context.getResponseWriter();
- StringWriter dumpingWriter = new StringWriter();
- ResponseWriter clonedWriter = writer.cloneWithWriter(dumpingWriter);
- context.setResponseWriter(clonedWriter);
- try {
- if (children) {
- this.renderChildren(context, component);
- } else if (component.getAttributes().get("label") != null) {
-
clonedWriter.write(component.getAttributes().get("label").toString());
- }
- } finally {
- clonedWriter.flush();
- context.setResponseWriter(writer);
- }
-
- return dumpingWriter.toString();
- }
-
-
-
-
- /**
- * Encodes script for state rendering in client mode
- *
- * @param context
- * @param component
- * @param state
- * @throws IOException
- */
- public String getShowStateScript(FacesContext context,
- UIComponent component, String state) throws IOException {
- StringBuffer script = new StringBuffer("\n");
- script.append(
- "RichFaces.$('" + component.getClientId(context)
- + "').showState('").append(state).append(
- "');");
- return script.toString();
- }
-
-
-
- /**
- * Encode initial javascript
- *
- * @param context
- * @param component
- * @throws IOException
- */
- public String getInitialScript(FacesContext context,
- UIComponent component, String state) throws IOException {
- AbstractProgressBar progressBar = (AbstractProgressBar) component;
- StringBuffer script = new StringBuffer();
- Map<String, Object> options = new HashMap<String, Object>();
- RendererUtils utils = getUtils();
-
- String clientId = component.getClientId(context);
-
- addToScriptHash(options, "mode",
component.getAttributes().get("mode"), "ajax");
- addToScriptHash(options, "minValue",
component.getAttributes().get("minValue"), "0");
- addToScriptHash(options, "maxValue",
component.getAttributes().get("maxValue"), "100");
- addToScriptHash(options, "context", getContext(component));
-
- Integer interval = new Integer(progressBar.getInterval());
- addToScriptHash(options, "pollinterval", interval);
- addToScriptHash(options, "enabled", progressBar.isEnabled());
- addToScriptHash(options, "pollId", progressBar.getClientId(context));
- addToScriptHash(options, "state", state, "initialState");
- addToScriptHash(options, "value",
NumberUtils.getNumber(component.getAttributes().get("value")));
- addToScriptHash(options, "onsubmit",
buildEventFunction(component.getAttributes().get("onsubmit")));
- script.append("new
RichFaces.ui.ProgressBar('").append(clientId).append("'");
- if (!options.isEmpty()) {
- script.append(",").append(ScriptUtils.toScript(options));
- }
- script.append(")\n;");
- return script.toString();
- }
-
- private Object buildEventFunction(Object eventFunction) {
- if(eventFunction != null && eventFunction.toString().length() > 0) {
- return "new Function(\"" + eventFunction.toString() +
"\");";
- }
- return null;
- }
-
- /**
- * Creates options map for AJAX requests
- *
- * @param clientId
- * @param progressBar
- * @param context
- * @return
- */
- public String getPollScript(FacesContext context, UIComponent component) {
- return "RichFaces.$('" + component.getClientId() +
"').__poll()";
-
- }
-
- public String getStopPollScript(FacesContext context, UIComponent component) {
- return "RichFaces.$('" + component.getClientId() +
"').disable()";
-
- }
-
- /**
* Check if component mode is AJAX
*
* @param component
* @return
*/
public boolean isAjaxMode(UIComponent component) {
- String mode = (String) component.getAttributes().get("mode");
- return "ajax".equalsIgnoreCase(mode);
- }
-
- public String getCurrentOrForcedState(FacesContext context, UIComponent component){
- String forcedState = getForcedState(context,component);
- if (forcedState != null) {
- return forcedState;
+ SwitchType mode = (SwitchType) component.getAttributes().get("mode");
+
+ if (mode == SwitchType.server) {
+ throw new IllegalArgumentException("Progress bar doesn't support
'server' mode");
}
- return getCurrentState(context, component);
+
+ return SwitchType.ajax == mode;
}
- public String getCurrentState(FacesContext context, UIComponent component){
+ protected ProgressBarState getCurrentState(FacesContext context, UIComponent
component){
Number minValue =
NumberUtils.getNumber(component.getAttributes().get("minValue"));
Number maxValue =
NumberUtils.getNumber(component.getAttributes().get("maxValue"));
Number value =
NumberUtils.getNumber(component.getAttributes().get("value"));
if (value.doubleValue() <= minValue.doubleValue()) {
- return "initialState";
+ return ProgressBarState.initialState;
} else if (value.doubleValue() > maxValue.doubleValue()) {
- return "completeState";
- } else {
- return "progressState";
+ return ProgressBarState.finishState;
+ } else {
+ return ProgressBarState.progressState;
}
}
- public String getShellStyle(FacesContext context, UIComponent component){
- return (!isSimpleMarkup(component)) ? "rf-pb-shl-dig "
- : "rf-pb-shl ";
+ protected String getStateDisplayStyle(String currentState, String state) {
+ if (currentState.equals(state)) {
+ return null;
+ }
+
+ return "display: none";
}
- public String getWidth(UIComponent component){
- Number value =
NumberUtils.getNumber(component.getAttributes().get("value"));
- Number minValue =
NumberUtils.getNumber(component.getAttributes().get("minValue"));
- Number maxValue =
NumberUtils.getNumber(component.getAttributes().get("maxValue"));
- Number percent = calculatePercent(value, minValue, maxValue);
-
- return String.valueOf(percent.intValue());
+ protected String getSubmitFunction(FacesContext facesContext, UIComponent component)
{
+ if (!isAjaxMode(component)) {
+ return null;
+ }
+
+ JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(facesContext,
component, AjaxRendererUtils.AJAX_FUNCTION_NAME);
+ AjaxEventOptions eventOptions = AjaxRendererUtils.buildEventOptions(facesContext,
component);
+ eventOptions.set("beforedomupdate", BEFORE_UPDATE_HANDLER);
+ eventOptions.set("complete", AFTER_UPDATE_HANDLER);
+ ajaxFunction.addParameter(eventOptions);
+ return ajaxFunction.toScript();
}
- public void renderInitialFacet(FacesContext context, UIComponent component) throws
IOException {
- renderFacet(context, component, INITIAL_FACET);
- }
+ public void encodeMetaComponent(FacesContext context, UIComponent component, String
metaComponentId)
+ throws IOException {
- public void renderCompleteFacet(FacesContext context, UIComponent component) throws
IOException {
- renderFacet(context, component, COMPLETE_FACET);
- }
+ if (AbstractProgressBar.STATE_META_COMPONENT_ID.equals(metaComponentId)) {
+ ProgressBarState state = getCurrentState(context, component);
+
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
+ ajaxContext.getResponseComponentDataMap().put(component.getClientId(context),
NumberUtils.getNumber(component.getAttributes().get("value")));
- private void renderFacet(FacesContext context, UIComponent component, String facet)
throws IOException {
- UIComponent headerFacet = component.getFacet(facet);
- if (headerFacet != null) {
- headerFacet.encodeAll(context);
- }
- }
-
-
- /**
- * Returns parameters attr
- *
- * @param component
- * @param renderer
- * @param percent
- * @return
- */
- public String getParameters(UIComponent component) {
- String parameters = (String) component.getAttributes()
- .get("parameters");
- return parameters;
- }
-
- /**
- * Returns context for macrosubstitution
- *
- * @param component
- * @return
- */
- private JSLiteral getContext(UIComponent component) {
- StringBuffer buffer = new StringBuffer();
- String parameters = getParameters(component);
- JSLiteral literal = null;
- if (parameters != null) {
- buffer.append("{").append(parameters).append("}");
- literal = new JSLiteral(buffer.toString());
- }
- return literal;
- }
-
- /**
- * Return true if component has children components
- *
- * @param component
- * @return
- */
- private boolean hasChildren(UIComponent component) {
- return (component.getChildCount() != 0);
- }
-
- /**
- * Returns true if markup should rendered as simple 2 divs
- *
- * @param component
- * @return
- */
- public boolean isSimpleMarkup(UIComponent component) {
- if (hasChildren(component)) {
- return false;
+ PartialResponseWriter partialResponseWriter =
context.getPartialViewContext().getPartialResponseWriter();
+ partialResponseWriter.startUpdate(state.getStateClientId(context,
component));
+
+ state.encodeStateForMetaComponent(context, component, PARTIAL_ENCODER);
+
+ partialResponseWriter.endUpdate();
} else {
- if (component.getAttributes().get("label") != null) {
- return false;
- }
+ throw new IllegalArgumentException(metaComponentId);
}
- return true;
}
-
-
-
- /**
- * Calculates percent value according to min & max value
- *
- * @param value
- * @param minValue
- * @param maxValue
- * @return
- */
- public Number calculatePercent(Number value, Number minValue,
- Number maxValue) {
- if (minValue.doubleValue() < value.doubleValue()
- && value.doubleValue() < maxValue.doubleValue()) {
- return (Number) ((value.doubleValue() - minValue.doubleValue()) * 100.0 /
(maxValue
- .doubleValue() - minValue.doubleValue()));
- } else if (value.doubleValue() <= minValue.doubleValue()) {
- return 0;
- } else if (value.doubleValue() >= maxValue.doubleValue()) {
- return 100;
- }
- return 0;
+
+ public void decodeMetaComponent(FacesContext context, UIComponent component, String
metaComponentId) {
+ throw new UnsupportedOperationException();
}
-
+
+ protected ProgressBarStateEncoder getEncoder(FacesContext facesContext, UIComponent
component) {
+ return isAjaxMode(component) ? PARTIAL_ENCODER : FULL_ENCODER;
+ }
}
Added:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarState.java
===================================================================
--- trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarState.java
(rev 0)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarState.java 2010-11-26
14:35:45 UTC (rev 20177)
@@ -0,0 +1,131 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.renderkit.html;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.richfaces.component.util.HtmlUtil;
+
+enum ProgressBarState {
+ initialState {
+ @Override
+ public String getStateClientId(FacesContext context, UIComponent component) {
+ return component.getClientId(context) + ".init";
+ }
+
+ @Override
+ public String getStyleClass(FacesContext context, UIComponent component) {
+ return HtmlUtil.concatClasses("rf-pb-init",
component.getAttributes().get("initialClass"));
+ }
+
+ @Override
+ public void encodeContent(FacesContext context, UIComponent component) throws
IOException {
+ UIComponent facet = component.getFacet("initial");
+ if (facet != null) {
+ facet.encodeAll(context);
+ }
+ }
+
+ @Override
+ public void encodeStateForMetaComponent(FacesContext context, UIComponent
component,
+ ProgressBarStateEncoder encoder) throws IOException {
+
+ encoder.encodeInitialState(context, component, this);
+ }
+
+ },
+
+ progressState {
+
+ @Override
+ public String getStateClientId(FacesContext context, UIComponent component) {
+ return component.getClientId(context) + ".lbl";
+ }
+
+ @Override
+ public String getStyleClass(FacesContext context, UIComponent component) {
+ return "rf-pb-lbl";
+ }
+
+ @Override
+ public void encodeContent(FacesContext context, UIComponent component) throws
IOException {
+ ResponseWriter responseWriter = context.getResponseWriter();
+
+ if (component.getChildCount() > 0) {
+ for (UIComponent child: component.getChildren()) {
+ child.encodeAll(context);
+ }
+ }
+
+ Object label = component.getAttributes().get("label");
+ if (label != null) {
+ responseWriter.writeText(label, null);
+ }
+ }
+
+ @Override
+ public void encodeStateForMetaComponent(FacesContext context, UIComponent
component,
+ ProgressBarStateEncoder encoder) throws IOException {
+
+ encoder.encodeProgressStateContent(context, component, this);
+ }
+ },
+
+ finishState {
+ @Override
+ public String getStateClientId(FacesContext context, UIComponent component) {
+ return component.getClientId(context) + ".fin";
+ }
+
+ @Override
+ public String getStyleClass(FacesContext context, UIComponent component) {
+ return HtmlUtil.concatClasses("rf-pb-fin",
component.getAttributes().get("finishClass"));
+ }
+
+ @Override
+ public void encodeContent(FacesContext context, UIComponent component) throws
IOException {
+ UIComponent facet = component.getFacet("finish");
+ if (facet != null) {
+ facet.encodeAll(context);
+ }
+ }
+
+ @Override
+ public void encodeStateForMetaComponent(FacesContext context, UIComponent
component,
+ ProgressBarStateEncoder encoder) throws IOException {
+
+ encoder.encodeCompleteState(context, component, this);
+ }
+ };
+
+ public abstract String getStateClientId(FacesContext context, UIComponent
component);
+
+ public abstract String getStyleClass(FacesContext context, UIComponent component);
+
+ public abstract void encodeContent(FacesContext context, UIComponent component)
throws IOException;
+
+ public abstract void encodeStateForMetaComponent(FacesContext context, UIComponent
component, ProgressBarStateEncoder encoder) throws IOException;
+}
\ No newline at end of file
Added:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarStateEncoder.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarStateEncoder.java
(rev 0)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarStateEncoder.java 2010-11-26
14:35:45 UTC (rev 20177)
@@ -0,0 +1,162 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.renderkit.html;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.richfaces.component.NumberUtils;
+import org.richfaces.component.util.HtmlUtil;
+import org.richfaces.renderkit.HtmlConstants;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+class ProgressBarStateEncoder {
+
+ private boolean renderContentAsPlaceHolders;
+
+ public ProgressBarStateEncoder(boolean renderContentAsPlaceHolders) {
+ super();
+ this.renderContentAsPlaceHolders = renderContentAsPlaceHolders;
+ }
+
+ protected String getContentStyle(boolean sameState) {
+ return sameState ? null : "display: none";
+ }
+
+ private void encodeStateFacet(FacesContext context, UIComponent component,
ProgressBarState state,
+ ProgressBarState currentState) throws IOException {
+ String clientId = state.getStateClientId(context, component);
+
+ ResponseWriter responseWriter = context.getResponseWriter();
+
+ responseWriter.startElement(HtmlConstants.DIV_ELEM, component);
+ responseWriter.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE,
state.getStyleClass(context, component), null);
+ responseWriter.writeAttribute(HtmlConstants.ID_ATTRIBUTE, clientId, null);
+
+ responseWriter.writeAttribute(HtmlConstants.STYLE_ATTRIBUTE,
getContentStyle(state == currentState), null);
+
+ if (!renderContentAsPlaceHolders || state == currentState) {
+ state.encodeContent(context, component);
+ }
+
+ responseWriter.endElement(HtmlConstants.DIV_ELEM);
+ }
+
+ public void encodeInitialState(FacesContext context, UIComponent component,
ProgressBarState currentState)
+ throws IOException {
+ encodeStateFacet(context, component, ProgressBarState.initialState,
currentState);
+ }
+
+ protected String getWidth(UIComponent component) {
+ Number value =
NumberUtils.getNumber(component.getAttributes().get("value"));
+ Number minValue =
NumberUtils.getNumber(component.getAttributes().get("minValue"));
+ Number maxValue =
NumberUtils.getNumber(component.getAttributes().get("maxValue"));
+ Number percent = calculatePercent(value, minValue, maxValue);
+
+ return String.valueOf(percent.intValue());
+ }
+
+ /**
+ * Calculates percent value according to min & max value
+ *
+ * @param value
+ * @param minValue
+ * @param maxValue
+ * @return
+ */
+ protected Number calculatePercent(Number value, Number minValue, Number maxValue) {
+ if (minValue.doubleValue() < value.doubleValue() &&
value.doubleValue() < maxValue.doubleValue()) {
+ return (Number) ((value.doubleValue() - minValue.doubleValue()) * 100.0 /
(maxValue.doubleValue() - minValue
+ .doubleValue()));
+ } else if (value.doubleValue() <= minValue.doubleValue()) {
+ return 0;
+ } else if (value.doubleValue() >= maxValue.doubleValue()) {
+ return 100;
+ }
+ return 0;
+ }
+
+ public void encodeProgressStateContent(FacesContext context, UIComponent component,
ProgressBarState currentState)
+ throws IOException {
+ ResponseWriter responseWriter = context.getResponseWriter();
+ String stateClientId = ProgressBarState.progressState.getStateClientId(context,
component);
+
+ responseWriter.startElement(HtmlConstants.DIV_ELEM, component);
+ responseWriter.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE,
+ ProgressBarState.progressState.getStyleClass(context, component), null);
+ responseWriter.writeAttribute(HtmlConstants.ID_ATTRIBUTE, stateClientId, null);
+
+ if (!renderContentAsPlaceHolders || currentState ==
ProgressBarState.progressState) {
+ ProgressBarState.progressState.encodeContent(context, component);
+ }
+
+ responseWriter.endElement(HtmlConstants.DIV_ELEM);
+ }
+
+ protected void encodeProgressStateProlog(FacesContext context, UIComponent component,
ProgressBarState currentState)
+ throws IOException {
+
+ ResponseWriter responseWriter = context.getResponseWriter();
+ responseWriter.startElement(HtmlConstants.DIV_ELEM, component);
+ responseWriter.writeAttribute(HtmlConstants.ID_ATTRIBUTE,
component.getClientId(context) + ".rmng",
+ null);
+ responseWriter.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE,
+ HtmlUtil.concatClasses("rf-pb-rmng",
component.getAttributes().get("remainingClass")), null);
+
+
+ responseWriter.writeAttribute(HtmlConstants.STYLE_ATTRIBUTE,
+ getContentStyle(currentState == ProgressBarState.progressState), null);
+
+ responseWriter.startElement(HtmlConstants.DIV_ELEM, component);
+ responseWriter.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE,
+ HtmlUtil.concatClasses("rf-pb-prgs",
component.getAttributes().get("progressClass")), null);
+ responseWriter.writeAttribute(HtmlConstants.ID_ATTRIBUTE,
component.getClientId(context) + ".prgs", null);
+ responseWriter.writeAttribute(HtmlConstants.STYLE_ATTRIBUTE, "width: "
+ getWidth(component) + "%", null);
+ responseWriter.endElement(HtmlConstants.DIV_ELEM);
+ }
+
+ protected void encodeProgressStateEpilog(FacesContext context, UIComponent component,
ProgressBarState currentState)
+ throws IOException {
+
+ ResponseWriter responseWriter = context.getResponseWriter();
+ responseWriter.endElement(HtmlConstants.DIV_ELEM);
+ }
+
+ public void encodeProgressState(FacesContext context, UIComponent component,
ProgressBarState currentState)
+ throws IOException {
+
+ encodeProgressStateProlog(context, component, currentState);
+ encodeProgressStateContent(context, component, currentState);
+ encodeProgressStateEpilog(context, component, currentState);
+ }
+
+ public void encodeCompleteState(FacesContext context, UIComponent component,
ProgressBarState currentState)
+ throws IOException {
+ encodeStateFacet(context, component, ProgressBarState.finishState,
currentState);
+ }
+}
Modified:
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/progressBar.ecss
===================================================================
---
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/progressBar.ecss 2010-11-26
14:26:49 UTC (rev 20176)
+++
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/progressBar.ecss 2010-11-26
14:35:45 UTC (rev 20177)
@@ -1,44 +1,48 @@
-.rf-pb-cnt{
-height : 13px;
-white-space : nowrap;
-width : 200px;
-}
-.rf-pb-upl{
-background-repeat : repeat-x;
-background-image :
"url(#{resource['org.richfaces.images:pbAniBg.gif']})";
-background-color : '#{richSkin.selectControlColor}';
-height : 13px;
+.rf-pb-rmng {
+ height: 13px;
+ white-space: nowrap;
+ width: 200px;
+
+ position: relative;
+ border-width: 1px;
+ border-style: solid;
+ border-color: '#{richSkin.panelBorderColor}';
+
+ overflow: hidden;
+ color: '#{richSkin.controlTextColor}';
+
+ font-family: '#{richSkin.generalFamilyFont}';
+ font-size: '#{richSkin.generalSizeFont}';
+ font-weight: bold;
+
+ text-align: center;
+ text-color: '#{richSkin.controlTextColor}';
+
+ background-color: '#{richSkin.controlBackgroundColor}';
+ padding: 0px;
}
-.rf-pb-upl-dig{
-overflow : hidden; position : absolute; top : 0px; left : 0px;
-border-color : '#{richSkin.panelBorderColor}';
+
+.rf-pb-prgs {
+ overflow: hidden;
+ border-color: '#{richSkin.panelBorderColor}';
+ background-repeat: repeat-x;
+ background-color: '#{richSkin.selectControlColor}';
+ height: 100%;
+ padding: 0px;
+ background-image:
"url(#{resource['org.richfaces.images:pbAniBg.gif']})";
}
-.rf-pb-shl{
-margin-bottom : 2px; border : 1px solid;
-background-color : '#{richSkin.controlBackgroundColor}';
-border-color : '#{richSkin.panelBorderColor}';
+
+.rf-pb-lbl {
+ position: absolute;
+ top: 0px;
+ left: 0px;
+ padding: 0px;
+ text-align: center;
+ width: 100%;
}
-.rf-pb-shl-dig{
-position : relative; margin-bottom : 2px; border : 1px solid; overflow: hidden;
-border-color : '#{richSkin.panelBorderColor}';
-color : '#{richSkin.controlTextColor}';
-font-family : '#{richSkin.generalFamilyFont}';
-font-size : '#{richSkin.generalSizeFont}';
-}
-.rf-pb-rmnd{
-text-align : center; font-weight : bold; position : relative;
-background-color : '#{richSkin.controlBackgroundColor}';
-text-color : '#{richSkin.controlTextColor}';
-height : 13px;
-width : 200px;
-padding: 0px;
-}
-.rf-pb-cmpltd{
-text-align : center; font-weight : bold; background-repeat : repeat-x;
-background-color : '#{richSkin.selectControlColor}';
-text-color : '#{richSkin.controlBackgroundColor}';
-height : 13px;
-width : 200px;
-padding: 0px;
-background-image :
"url(#{resource['org.richfaces.images:pbAniBg.gif']})";
-}
+
+.rf-pb-init, .rf-pb-fin {
+ color: '#{richSkin.generalTextColor}';
+ font-family: '#{richSkin.generalFamilyFont}';
+ font-size: '#{richSkin.generalSizeFont}';
+}
\ No newline at end of file
Modified:
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/progressBar.js
===================================================================
---
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/progressBar.js 2010-11-26
14:26:49 UTC (rev 20176)
+++
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/progressBar.js 2010-11-26
14:35:45 UTC (rev 20177)
@@ -1,33 +1,38 @@
-//ProgressBar = {};
-//ProgressBar = Class.create();
(function ($, rf) {
rf.ui = rf.ui || {};
var defaultOptions = {
- mode: "ajax",
minValue: 0,
- maxValue: 100,
- state: "initialState"
+ maxValue: 100
};
+ var stateSelectors = {
+ initial: '> .rf-pb-init',
+ progress: '> .rf-pb-rmng',
+ finish: '> .rf-pb-fin'
+ };
+
// Constructor definition
rf.ui.ProgressBar = function(componentId, options) {
// call constructor of parent class
$super.constructor.call(this, componentId);
this.id = componentId;
- this.attachToDom(this.id);
+ this.__elt = this.attachToDom(this.id);
this.options = $.extend({}, defaultOptions, options);
this.enabled = this.options.enabled;
- this.state = this.options.state;
- this.value = this.options.value;
this.minValue = this.options.minValue;
this.maxValue = this.options.maxValue;
- var component = this;
- this.options.beforedomupdate = function(event) {
- component.__onComplete(event.data);
- }
+ this.__setValue(this.options.value);
+ if (this.options.submitFunction) {
+ this.submitFunction = new Function("beforeUpdateHandler",
"afterUpdateHandler", "event", this.options.submitFunction);
+ this.__poll();
+ }
+
+ if (this.options.onfinish) {
+ rf.Event.bind(this.__elt, "finish", new Function("event",
this.options.onfinish));
+ }
};
// Extend component class and add protected methods from parent class to our container
@@ -38,57 +43,42 @@
$.extend(rf.ui.ProgressBar.prototype, (function() {
return {
- name:"ProgressBar",
+ name: "ProgressBar",
- __updateComponent: function (data) {
- this.setValue(this.value);
- if (!data['enabled']) {
- this.disable();
+ __isInitialState: function() {
+ return parseFloat(this.value) <= parseFloat(this.getMinValue());
+ },
+
+ __isProgressState: function() {
+ return !this.__isInitialState() && !this.__isFinishState();
+ },
+
+ __isFinishState: function() {
+ return parseFloat(this.value) > parseFloat(this.getMaxValue());
+ },
+
+ __beforeUpdate: function(event) {
+ if (event.componentData && typeof event.componentData[this.id] !=
'undefined') {
+ this.setValue(event.componentData[this.id]);
}
- $(rf.getDomElement(this.id +
":complete")).addClass(data['completeClass']);
- $(rf.getDomElement(this.id +
":remain")).addClass(data['remainClass']);
- $(rf.getDomElement(this.id)).addClass(data['styleClass']);
-
- if (this.options.pollinterval != data['interval']) {
- this.options.pollinterval = data['interval'];
- }
},
- __forceState: function (state, oncomplete) {
- var params = {};
- params['forcePercent'] = state;
- params[this.id] = this.id;
-
- var options = {
- parameters: params,
- oncomplete: oncomplete
- };
-
- var form = $(rf.getDomElement(this.id)).closest('form');
- rf.ajax(form.attr('id'), null, options);
+ __afterUpdate: function(event) {
+ this.__poll();
},
- __getContext: function () {
- var context = this.context || {};
- context['minValue'] = (this.minValue == 0 ? "0" : this.minValue);
- context['maxValue'] = (this.maxValue == 0 ? "0" : this.maxValue);
- context['value'] = (this.value == 0 ? "0" : this.value);
- if (this.progressVar) {
- context[this.progressVar] = context['value'];
- }
- return context;
+ __submit: function() {
+ this.submitFunction.call(this, $.proxy(this.__beforeUpdate, this),
$.proxy(this.__afterUpdate, this));
},
-
- __renderLabel: function (markup, context) {
- if (!markup || this.state != "progressState") {
- return;
+
+ __poll: function(immediate) {
+ if (this.enabled) {
+ if (immediate) {
+ this.__submit();
+ } else {
+ this.__pollTimer = setTimeout($.proxy(this.__submit, this),
this.options.interval);
+ }
}
- var html = rf.interpolate(markup, context || this.__getContext());
- var remain = rf.getDomElement(this.id + ":remain");
- var complete = rf.getDomElement(this.id + ":complete");
- if (remain && complete){
- remain.innerHTML = complete.innerHTML = html;
- }
},
__calculatePercent: function(v) {
@@ -116,36 +106,38 @@
return this.value;
},
- showState: function (state) {
- this.state = state;
-
- var stateElt = $(rf.getDomElement(this.id + ":" + state));
+ __showState: function (state) {
+ var stateElt = $(stateSelectors[state], this.__elt);
stateElt.show().siblings().hide();
},
- setValue: function(val) {
- this.value = this.__getPropertyOrObject(val, "value");
+ __setValue: function(val, initialStateSetup) {
+ this.value = parseFloat(this.__getPropertyOrObject(val, "value"));
- if (!this.isAjaxMode()) {
- if (parseFloat(this.getValue()) <= parseFloat(this.getMinValue())) {
- this.showState("initialState");
- } else if (parseFloat(this.getValue()) > parseFloat(this.getMaxValue())) {
- this.showState("completeState");
- } else {
- this.showState("progressState");
- }
+ if (this.__isFinishState()) {
+ this.disable();
}
-
- if (this.isAjaxMode() || this.state == "progressState") {
- if (this.markup) {
- this.__renderLabel(this.markup, this.__getContext());
- }
-
- var p = this.__calculatePercent(this.getValue());
- $(rf.getDomElement(this.id + ":upload")).css('width', p +
"%");
+ },
+
+ __updateVisualState: function() {
+ if (this.__isInitialState()) {
+ this.__showState("initial");
+ } else if (this.__isFinishState()) {
+ rf.Event.callHandler(this.__elt, "finish");
+ this.__showState("finish");
+ } else {
+ this.__showState("progress");
+
+ var p = this.__calculatePercent(this.value);
+ $(".rf-pb-prgs", this.__elt).css('width', p + "%");
}
},
+ setValue: function(val) {
+ this.__setValue(val);
+ this.__updateVisualState();
+ },
+
getMaxValue: function() {
return this.maxValue;
},
@@ -154,16 +146,17 @@
return this.minValue;
},
- getMode: function () {
- return this.options.mode;
- },
-
isAjaxMode: function () {
- return (this.getMode() == "ajax");
+ return !!this.submitFunction;
},
disable: function () {
- this.enabled = false;
+ if (this.__pollTimer) {
+ clearTimeout(this.__pollTimer);
+ this.__pollTimer = null;
+ }
+
+ this.enabled = false;
},
enable: function () {
@@ -173,75 +166,22 @@
this.enabled = true;
- if (!this.isAjaxMode()) {
- this.showState("progressState");
- this.setValue(this.getMinValue() + 1);
- } else if (this.value <= this.getMaxValue()) {
- this.__poll();
+ if (this.isAjaxMode()) {
+ this.__poll(true);
}
},
isEnabled: function() {
return this.enabled;
- }
+ },
+
+ destroy: function() {
+ this.disable();
+ this.__elt = null;
+ $super.destroy.call(this);
+ }
}
} ()));
- var onComplete = function (data) {
- if (!rf.getDomElement(this.id) || !this.isEnabled()) {
- return;
- }
- if (data) {
- this.value = data['value'];
- if (this.state == "progressState") {
- if (this.value > this.getMaxValue()) {
- this.disable();
- this.__forceState("completeState");
- return;
- }
- this.__updateComponent(data);
- this.__renderLabel(data['markup'], data['context']);
- } else if (this.state == "initialState" && this.value >
this.getMinValue()) {
- this.state = "progressState";
- this.__forceState("progressState");
- return;
- }
- this.__poll();
- }
-
- };
- var poll = function () {
- if (this.isEnabled()){
- this.options.parameters = this.options.parameters || {};
- this.options.parameters['percent'] = "percent";
- this.options.parameters[this.id] = this.id;
- var component = this;
- window.setTimeout(function(){
- if(component.options.onsubmit){
- var onsubmit = eval(component.options.onsubmit)
- var result = onsubmit.call(component);
- if (result!=false) {
- result = true;
- }
- if(result){
- rf.ajax(component.options.pollId, null, component.options);
- }
- }else{
- rf.ajax(component.options.pollId, null, component.options);
- }
-
- },this.options.pollinterval);
- }
- };
-
- /*
- * Prototype definition
- */
- $.extend(rf.ui.ProgressBar.prototype, (function () {
- return {
- __onComplete: onComplete,
- __poll: poll
- };
- })());
})(jQuery, RichFaces);
Modified: trunk/ui/output/ui/src/main/templates/progressBar.template.xml
===================================================================
--- trunk/ui/output/ui/src/main/templates/progressBar.template.xml 2010-11-26 14:26:49 UTC
(rev 20176)
+++ trunk/ui/output/ui/src/main/templates/progressBar.template.xml 2010-11-26 14:35:45 UTC
(rev 20177)
@@ -11,71 +11,38 @@
<cdk:superclass>org.richfaces.renderkit.html.ProgressBarBaseRenderer</cdk:superclass>
<cdk:component-family>org.richfaces.ProgressBarRenderer</cdk:component-family>
<cdk:renderer-type>org.richfaces.ProgressBarRenderer</cdk:renderer-type>
+ <cdk:renders-children>true</cdk:renders-children>
</cc:interface>
<cc:implementation>
- <c:choose>
- <c:when test="#{isAjaxMode(component)}">
- <cdk:object type="java.lang.String" name="state"
value="#{getCurrentOrForcedState(facesContext, component)}" />
-
- <c:if test="#{state eq 'initialState'}">
- <div id="#{clientId}"
class="#{component.attributes['initialClass']}"
style="#{component.attributes['style']}">
- <cdk:call expression="renderInitialFacet(facesContext,
component)"/>
- </div>
- </c:if>
- <c:if test="#{state eq 'completeState'}">
- <div id="#{clientId}"
class="#{component.attributes['finishClass']}"
style="#{component.attributes['style']}">
- <cdk:call expression="renderCompleteFacet(facesContext,
component)"/>
- </div>
- </c:if>
- <c:if test="#{state eq 'progressState'}">
- <cdk:object type="java.lang.String" name="shellStyle"
value="#{getShellStyle(facesContext, component)}" />
- <div cdk:passThroughWithExclusions="onclick, ondblclick, onmouseup,
onmousedown, onmousemove, onmouseover, onmouseout" id="#{clientId}"
class="rf-pb-cnt #{shellStyle} #{component.attributes['styleClass']}"
style="#{component.attributes['style']}">
- <c:if test="#{!isSimpleMarkup(component)}">
- <div class="rf-pb-rmnd #{component.attributes['remainClass']}"
id="#{clientId}:remain"
style="#{component.attributes['style']}"/>
- <div class="rf-pb-upl-dig" id="#{clientId}:upload"
style="#{component.attributes['style']};
width:#{getWidth(component)}%;">
- <div class="rf-pb-cmpltd
#{component.attributes['completeClass']}" id="#{clientId}:complete"
style="#{component.attributes['style']}"/>
- </div>
- </c:if>
- <c:if test="#{isSimpleMarkup(component)}">
- <div class="rf-pb-upl #{component.attributes['completeClass']}"
id="#{clientId}:upload" style="#{component.attributes['style']};
width:#{getWidth(component)}%;"/>
- </c:if>
- <script type="text/javascript">
- #{getInitialScript(facesContext, component, 'progressState')}
- #{getPollScript(facesContext, component)}
- </script>
-
- </div>
- </c:if>
- </c:when>
- <c:otherwise>
- <div id="#{clientId}" >
- <div id="#{clientId}:initialState"
class="#{component.attributes['initialClass']}"
style="#{component.attributes['style']} display:none;">
- <cdk:call expression="renderInitialFacet(facesContext, component)"/>
- </div>
- <cdk:object type="java.lang.String" name="shellStyle"
value="#{getShellStyle(facesContext, component)}" />
- <div cdk:passThroughWithExclusions="onclick, ondblclick, onmouseup,
onmousedown, onmousemove, onmouseover, onmouseout"
id="#{clientId}:progressState" class="rf-pb-cnt #{shellStyle}
#{component.attributes['styleClass']}"
style="#{component.attributes['style']} display:none;">
- <c:if test="#{!isSimpleMarkup(component)}">
- <div class="rf-pb-rmnd #{component.attributes['remainClass']}"
id="#{clientId}:remain"
style="#{component.attributes['style']}"/>
- <div class="rf-pb-upl-dig" id="#{clientId}:upload"
style="#{component.attributes['style']};
width=#{getWidth(component)}%;">
- <div class="rf-pb-cmpltd
#{component.attributes['completeClass']}" id="#{clientId}:complete"
style="#{component.attributes['style']}"/>
- </div>
- </c:if>
- <c:if test="#{isSimpleMarkup(component)}">
- <div class="rf-pb-upl #{component.attributes['completeClass']}"
id="#{clientId}:upload" style="#{component.attributes['style']};
width=#{getWidth(component)}%;"/>
- </c:if>
- </div>
- <div id="#{clientId}:completeState"
class="#{component.attributes['finishClass']}"
style="#{component.attributes['style']} display:none;">
- <cdk:call expression="renderCompleteFacet(facesContext,
component)"/>
- </div>
- <cdk:object type="java.lang.String" name="state"
value="#{getCurrentState(facesContext, component)}" />
+
+ <div id="#{clientId}" cdk:passThroughWithExclusions="">
+ <cdk:object name="encoder"
value="#{getEncoder(facesContext, component)}"
type="ProgressBarStateEncoder" />
+ <cdk:object name="currentState"
value="#{getCurrentState(facesContext, component)}"
type="ProgressBarState" />
+
+ <cdk:call>
+ encoder.encodeInitialState(facesContext, component, currentState);
+ </cdk:call>
+
+ <cdk:call>
+ encoder.encodeCompleteState(facesContext, component, currentState);
+ </cdk:call>
+
+ <cdk:call>
+ encoder.encodeProgressState(facesContext, component, currentState);
+ </cdk:call>
+
<script type="text/javascript">
- #{getInitialScript(facesContext, component, state)}
- #{getShowStateScript(facesContext, component, state)}
+ <cdk:scriptObject name="options">
+ <cdk:scriptOption name="submitFunction"
value="#{getSubmitFunction(facesContext, component)}" />
+ <cdk:scriptOption name="minValue"
value="#{component.attributes['minValue']}" defaultValue="0"
/>
+ <cdk:scriptOption name="maxValue"
value="#{component.attributes['maxValue']}" defaultValue="100"
/>
+
+ <cdk:scriptOption attributes="interval enabled value
onfinish" />
+ </cdk:scriptObject>
+
+ new RichFaces.ui.ProgressBar(#{toScriptArgs(clientId, options)});
</script>
</div>
-
- </c:otherwise>
- </c:choose>
</cc:implementation>
</cdk:root>
\ No newline at end of file