Author: andrei_exadel
Date: 2008-03-18 06:23:21 -0400 (Tue, 18 Mar 2008)
New Revision: 6889
Modified:
trunk/ui/progressBAR/src/main/java/org/richfaces/component/UIProgressBar.java
trunk/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java
Log:
RF-2573
Modified: trunk/ui/progressBAR/src/main/java/org/richfaces/component/UIProgressBar.java
===================================================================
---
trunk/ui/progressBAR/src/main/java/org/richfaces/component/UIProgressBar.java 2008-03-18
09:26:47 UTC (rev 6888)
+++
trunk/ui/progressBAR/src/main/java/org/richfaces/component/UIProgressBar.java 2008-03-18
10:23:21 UTC (rev 6889)
@@ -32,7 +32,7 @@
import org.richfaces.renderkit.AbstractProgressBarRenderer;
/**
- * Class provides base component class for progress bar
+ * Class provides base component class for progress bar
*
* @author "Andrey Markavtsov"
*
@@ -40,233 +40,247 @@
// TODO add @since declaration
public abstract class UIProgressBar extends UIPoll {
- /** Logger */
- private final Log logger = LogFactory.getLog(UIProgressBar.class);
+ /** Logger */
+ private final Log logger = LogFactory.getLog(UIProgressBar.class);
- /** Component type */
- public static final String COMPONENT_TYPE = "org.richfaces.ProgressBar";
+ /** Component type */
+ public static final String COMPONENT_TYPE = "org.richfaces.ProgressBar";
- /** Component family */
- public static final String COMPONENT_FAMILY = "org.richfaces.ProgressBar";
+ /** 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";
+ /** Request parameter name containing component state to render */
+ public static final String FORCE_PERCENT_PARAM = "forcePercent";
- /** 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";
-
- /** Complete class attribute name */
- private static final String _completeClass = "completeClass";
+ /** Percent param name */
+ private static final String PERCENT_PARAM = "percent";
- /** Remain class attribute name */
- private static final String _remainClass = "remainClass";
+ /** Max value attribute name */
+ private static final String _maxValue = "maxValue";
- /** Style class attribute name */
- private static final String _styleClass = "styleClass";
-
- /** Markup data key */
- private static final String _markup = "markup";
-
- /** Context key */
- private static final String _context = "context";
+ /** Min value attribute name */
+ private static final String _minValue = "minValue";
- /**
- * Method performs broadcasting of jsf events to progress bar component
- *
- * @param event - Faces Event instance
- */
- public void broadcast(FacesEvent event) throws AbortProcessingException {
+ /** Enabled attribute name */
+ private static final String _enabled = "enabled";
- FacesContext facesContext = FacesContext.getCurrentInstance();
- AjaxContext ajaxContext = AjaxContextImpl
- .getCurrentInstance(facesContext);
- HttpServletRequest request = (HttpServletRequest) facesContext
- .getExternalContext().getRequest();
- Map params = request.getParameterMap();
- String clientId = this.getClientId(facesContext);
+ /** Enabled attribute name */
+ private static final String _interval = "interval";
- if (!params.containsKey(clientId)) {
- return;
- }
+ /** Complete class attribute name */
+ private static final String _completeClass = "completeClass";
- if (event instanceof ActionEvent) {
- ActionListener listeners[] = getActionListeners();
- for (ActionListener l : listeners) {
- l.processAction((ActionEvent) event);
- }
- } else if (event instanceof AjaxEvent) {
+ /** Remain class attribute name */
+ private static final String _remainClass = "remainClass";
- if (!params.containsKey(FORCE_PERCENT_PARAM)
- && params.containsKey(PERCENT_PARAM)) {
- Number value =
getNumber(this.getAttributes().get(RendererUtils.HTML.value_ATTRIBUTE));
- ajaxContext.removeRenderedArea(clientId);
- ajaxContext
- .setResponseData(getResponseData(value, facesContext));
+ /** Style class attribute name */
+ private static final String _styleClass = "styleClass";
- Object reRender = this.getAttributes().get(AjaxRendererUtils.AJAX_REGIONS_ATTRIBUTE);
- Set<String> ajaxRegions = AjaxRendererUtils.asSet(reRender);
+ /** Markup data key */
+ private static final String _markup = "markup";
- if (ajaxRegions != null) {
- for (Iterator<String> iter = ajaxRegions.iterator(); iter.hasNext();) {
- String id = iter.next();
- ajaxContext.addComponentToAjaxRender(this, id);
- }
+ /** Context key */
+ private static final String _context = "context";
+
+ /**
+ * 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();
+ AjaxContext ajaxContext = AjaxContextImpl
+ .getCurrentInstance(facesContext);
+ HttpServletRequest request = (HttpServletRequest) facesContext
+ .getExternalContext().getRequest();
+ Map params = request.getParameterMap();
+ String clientId = this.getClientId(facesContext);
+
+ if (!params.containsKey(clientId)) {
+ return;
}
- } else if (params.containsKey(FORCE_PERCENT_PARAM)) {
- if (logger.isDebugEnabled()) {
- logger.debug("Force state: " +
this.getClientId(facesContext));
- }
- ajaxContext.addComponentToAjaxRender(this);
- }
- }
- }
- /**
- * Returns ajax response data
- *
- * @param uiComponent
- * @param percent
- * @return
- */
- private Map<Object, Object> getResponseData(Number value,
- FacesContext facesContext) {
+ if (event instanceof ActionEvent) {
+ ActionListener listeners[] = getActionListeners();
+ for (ActionListener l : listeners) {
+ l.processAction((ActionEvent) event);
+ }
+ } else if (event instanceof AjaxEvent) {
- AbstractProgressBarRenderer renderer = (AbstractProgressBarRenderer) this
- .getRenderer(facesContext);
+ if (!params.containsKey(FORCE_PERCENT_PARAM)
+ && params.containsKey(PERCENT_PARAM)) {
+ Number value = getNumber(this.getAttributes().get(
+ RendererUtils.HTML.value_ATTRIBUTE));
+ ajaxContext.removeRenderedArea(clientId);
+ ajaxContext
+ .setResponseData(getResponseData(value, facesContext));
- Map<Object, Object> map = new HashMap<Object, Object>();
- map.put(RendererUtils.HTML.value_ATTRIBUTE, value);
- map.put(_interval, this.getInterval());
+ Object reRender = this.getAttributes().get(
+ AjaxRendererUtils.AJAX_REGIONS_ATTRIBUTE);
+ Set<String> ajaxRegions = AjaxRendererUtils.asSet(reRender);
- if (this.getAttributes().get(RendererUtils.HTML.style_ATTRIBUTE) != null) {
- map.put(RendererUtils.HTML.style_ATTRIBUTE,
this.getAttributes().get(RendererUtils.HTML.style_ATTRIBUTE));
+ if (ajaxRegions != null) {
+ for (Iterator<String> iter = ajaxRegions.iterator(); iter
+ .hasNext();) {
+ String id = iter.next();
+ ajaxContext.addComponentToAjaxRender(this, id);
+ }
+ }
+ } else if (params.containsKey(FORCE_PERCENT_PARAM)) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Force state: "
+ + this.getClientId(facesContext));
+ }
+ ajaxContext.addComponentToAjaxRender(this);
+ }
+ }
}
- boolean enabled = (Boolean) this.getAttributes().get(_enabled);
- map.put(_enabled, Boolean.toString(enabled));
+ /**
+ * Returns ajax response data
+ *
+ * @param uiComponent
+ * @param percent
+ * @return
+ */
+ private Map<Object, Object> getResponseData(Number value,
+ FacesContext facesContext) {
- if (!isSimple(renderer)) {
- map.put(_markup, getMarkup(facesContext, renderer));
- map.put(_context, getContext(renderer, value));
- }
+ AbstractProgressBarRenderer renderer = (AbstractProgressBarRenderer) this
+ .getRenderer(facesContext);
- addStyles2Responce(map, _completeClass, this.getAttributes().get(_completeClass));
- addStyles2Responce(map, _remainClass, this.getAttributes().get(_remainClass));
- addStyles2Responce(map, _styleClass, this.getAttributes().get(_styleClass));
- return map;
+ Map<Object, Object> map = new HashMap<Object, Object>();
+ map.put(RendererUtils.HTML.value_ATTRIBUTE, value);
+ map.put(_interval, this.getInterval());
- }
+ if (this.getAttributes().get(RendererUtils.HTML.style_ATTRIBUTE) != null) {
+ map.put(RendererUtils.HTML.style_ATTRIBUTE, this.getAttributes()
+ .get(RendererUtils.HTML.style_ATTRIBUTE));
+ }
- /**
- * Returns context for macrosubstitution
- *
- * @param renderer
- * @param percent
- * @return
- */
- private JSLiteral getContext(AbstractProgressBarRenderer 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)
+ boolean enabled = (Boolean) this.getAttributes().get(_enabled);
+ map.put(_enabled, Boolean.toString(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;
+
+ }
+
+ /**
+ * Returns context for macrosubstitution
+ *
+ * @param renderer
+ * @param percent
+ * @return
+ */
+ private JSLiteral getContext(AbstractProgressBarRenderer 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()));
- String parameters = renderer.getParameters(this);
- if (parameters != null) {
- buffer.append(",");
- buffer.append(parameters);
+ String parameters = renderer.getParameters(this);
+ if (parameters != null) {
+ buffer.append(",");
+ buffer.append(parameters);
+ }
+ buffer.append("}");
+ return new JSLiteral(buffer.toString());
}
- buffer.append("}");
- return new JSLiteral(buffer.toString());
- }
- /**
- * Return true if markup is simple
- *
- * @return
- */
- private boolean isSimple(AbstractProgressBarRenderer renderer) {
- return renderer.isSimpleMarkup(this);
- }
+ /**
+ * Return true if markup is simple
+ *
+ * @return
+ */
+ private boolean isSimple(AbstractProgressBarRenderer renderer) {
+ return renderer.isSimpleMarkup(this);
+ }
- /**
- * Returns label markup
- *
- * @param context
- * @param renderer
- * @return
- */
- private JSLiteral getMarkup(FacesContext context,
- AbstractProgressBarRenderer renderer) {
- JSLiteral literal = null;
- try {
- StringBuffer markup = renderer.getMarkup(context, this);
- if (markup != null) {
- literal = new JSLiteral(markup.toString());
- }
- } catch (Exception e) {
+ /**
+ * Returns label markup
+ *
+ * @param context
+ * @param renderer
+ * @return
+ */
+ private JSLiteral getMarkup(FacesContext context,
+ AbstractProgressBarRenderer renderer) {
+ JSLiteral literal = null;
+ try {
+ StringBuffer markup = renderer.getMarkup(context, this);
+ if (markup != null) {
+ literal = new JSLiteral(markup.toString());
+ }
+ } catch (Exception e) {
+ }
+ return literal;
}
- return literal;
- }
- /**
- * 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);
+ /**
+ * 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);
+ }
}
- }
- /**
- * Converts value attr to number value
- *
- * @param v - value attr
- * @return result
- */
- public Number getNumber(Object v) {
- Number result = null;
- if (v != null) {
- try {
- if (v instanceof String) { // String
- result = Double.parseDouble((String) v);
- } else {
- Number n = (Number) v;
- if ((n instanceof BigDecimal) || (n instanceof Double) // Double or BigDecimal
- || (n instanceof Float)) {
- result = n.floatValue();
- } else if (n instanceof Integer || n instanceof Long) { //
Integer
- result = n.longValue();
- }
+ /**
+ * Converts value attr to number value
+ *
+ * @param v -
+ * value attr
+ * @return result
+ */
+ public Number getNumber(Object v) {
+ Number result = null;
+ if (v != null) {
+ try {
+ if (v instanceof String) { // String
+ result = Double.parseDouble((String) v);
+ } else {
+ Number n = (Number) v;
+ if ((n instanceof BigDecimal) || (n instanceof Double) // Double
+ // or
+ // BigDecimal
+ || (n instanceof Float)) {
+ result = n.floatValue();
+ } else if (n instanceof Integer || n instanceof Long) { // Integer
+ result = n.longValue();
+ }
+ }
+ } catch (Exception e) {
+ e.getMessage();
+ }
+ return result;
}
- } catch (Exception e) {
- e.getMessage();
- }
+ return new Integer(0);
}
- return result;
- }
}
Modified:
trunk/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java
===================================================================
---
trunk/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java 2008-03-18
09:26:47 UTC (rev 6888)
+++
trunk/ui/progressBAR/src/main/java/org/richfaces/renderkit/AbstractProgressBarRenderer.java 2008-03-18
10:23:21 UTC (rev 6889)
@@ -42,652 +42,702 @@
*/
public class AbstractProgressBarRenderer extends TemplateEncoderRendererBase {
- /** Ajax function performing polling */
- private static final String AJAX_POLL_FUNCTION = "A4J.AJAX.Poll";
+ /** Ajax function performing polling */
+ private static final String AJAX_POLL_FUNCTION = "A4J.AJAX.Poll";
- /*
- * (non-Javadoc)
- *
- * @see
org.ajax4jsf.renderkit.AjaxCommandRendererBase#doDecode(javax.faces.context.FacesContext,
- * javax.faces.component.UIComponent)
- */
- @Override
- protected void doDecode(FacesContext facesContext, UIComponent uiComponent) {
- new AjaxEvent(uiComponent).queue();
- uiComponent.queueEvent(new ActionEvent(uiComponent));
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.renderkit.AjaxCommandRendererBase#doDecode(javax.faces.context.FacesContext,
+ * javax.faces.component.UIComponent)
+ */
+ @Override
+ protected void doDecode(FacesContext facesContext, UIComponent uiComponent) {
+ new AjaxEvent(uiComponent).queue();
+ uiComponent.queueEvent(new ActionEvent(uiComponent));
+ }
- /**
- * Render progress state forced from javascript
- *
- * @param state
- * @param context
- * @param component
- * @throws IOException
- */
- public void renderForcedState(String state, FacesContext context,
- UIComponent component) throws IOException {
- if ("initialState".equals(state)) {
- encodeInitialState(context, component, true);
- } else if ("progressState".equals(state)) {
- encodeProgressState(context, component, true);
- } else if ("completeState".equals(state)) {
- encodeCompletedState(context, component, true);
+ /**
+ * Render progress state forced from javascript
+ *
+ * @param state
+ * @param context
+ * @param component
+ * @throws IOException
+ */
+ public void renderForcedState(String state, FacesContext context,
+ UIComponent component) throws IOException {
+ if ("initialState".equals(state)) {
+ encodeInitialState(context, component, true);
+ } else if ("progressState".equals(state)) {
+ encodeProgressState(context, component, true);
+ } else if ("completeState".equals(state)) {
+ encodeCompletedState(context, component, true);
+ }
+ component.getAttributes().remove(UIProgressBar.FORCE_PERCENT_PARAM);
}
- component.getAttributes().remove(UIProgressBar.FORCE_PERCENT_PARAM);
- }
-
- /**
- * Gets state forced from javascript
- *
- * @param component
- * @return
- */
- public String getForcedState(FacesContext context, UIComponent component) {
- String forcedState = null;
- HttpServletRequest request =
(HttpServletRequest)context.getExternalContext().getRequest();
- Map params = request.getParameterMap();
- if (params.containsKey(UIProgressBar.FORCE_PERCENT_PARAM)) {
- String[] str = (String[]) params.get(UIProgressBar.FORCE_PERCENT_PARAM);
- forcedState = str[0];
+
+ /**
+ * Gets state forced from javascript
+ *
+ * @param component
+ * @return
+ */
+ public String getForcedState(FacesContext context, UIComponent component) {
+ String forcedState = null;
+ HttpServletRequest request = (HttpServletRequest) context
+ .getExternalContext().getRequest();
+ Map params = request.getParameterMap();
+ if (params.containsKey(UIProgressBar.FORCE_PERCENT_PARAM)) {
+ String[] str = (String[]) params
+ .get(UIProgressBar.FORCE_PERCENT_PARAM);
+ forcedState = str[0];
+ }
+ return forcedState;
}
- return forcedState;
- }
- /**
- * Renderes label markup
- *
- * @param context
- * @param component
- * @return
- */
- public StringBuffer getMarkup(FacesContext context, UIComponent component) {
- StringBuffer result = null;
- CountingOutputWriter customWriter = new CountingOutputWriter();
- try {
- if (hasChildren(component)) {
- ResponseWriter writer = context.getResponseWriter();
+ /**
+ * Renderes label markup
+ *
+ * @param context
+ * @param component
+ * @return
+ */
+ public StringBuffer getMarkup(FacesContext context, UIComponent component) {
+ StringBuffer result = null;
+ CountingOutputWriter customWriter = new CountingOutputWriter();
+ try {
+ if (hasChildren(component)) {
+ ResponseWriter writer = context.getResponseWriter();
- String defaultRenderKitId = context.getApplication()
- .getDefaultRenderKitId();
- if (null == defaultRenderKitId) {
- defaultRenderKitId = RenderKitFactory.HTML_BASIC_RENDER_KIT;
- }
- RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
- .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
- RenderKit renderKit = renderKitFactory.getRenderKit(context,
- defaultRenderKitId);
+ String defaultRenderKitId = context.getApplication()
+ .getDefaultRenderKitId();
+ if (null == defaultRenderKitId) {
+ defaultRenderKitId = RenderKitFactory.HTML_BASIC_RENDER_KIT;
+ }
+ RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ RenderKit renderKit = renderKitFactory.getRenderKit(context,
+ defaultRenderKitId);
- ResponseWriter responseWriter = renderKit.createResponseWriter(
- customWriter, null, "UTF-8");
- context.setResponseWriter(responseWriter);
- writeScriptBody(context, component, true);
- result = customWriter.getContent();
- if (writer != null) {
- context.setResponseWriter(writer);
+ ResponseWriter responseWriter = renderKit.createResponseWriter(
+ customWriter, null, "UTF-8");
+ context.setResponseWriter(responseWriter);
+ writeScriptBody(context, component, true);
+ result = customWriter.getContent();
+ if (writer != null) {
+ context.setResponseWriter(writer);
+ }
+
+ } else {
+ writeScriptBody(customWriter, (String) component
+ .getAttributes().get("label"));
+ result = customWriter.getContent();
+ }
+ } catch (Exception e) {
+ e.getMessage();
}
- } else {
- writeScriptBody(customWriter, (String) component
- .getAttributes().get("label"));
- result = customWriter.getContent();
- }
- } catch (Exception e) {
- e.getMessage();
+ return result;
+
}
- return result;
+ /**
+ * Methods encodes AJAX script for polling
+ *
+ * @param context -
+ * faces context
+ * @param component -
+ * component instance
+ * @throws IOException -
+ * IOException
+ */
+ public void encodePollScript(FacesContext context, UIComponent component)
+ throws IOException {
- }
+ ResponseWriter writer = context.getResponseWriter();
+ UIProgressBar progressBar = (UIProgressBar) component;
+ String clientId = component.getClientId(context);
+ StringBuffer pollScript = new StringBuffer("\n");
+ StringBuffer script = new StringBuffer("\n");
+ if (isAjaxMode(component) && progressBar.isEnabled()) {
+ JSFunction function = AjaxRendererUtils.buildAjaxFunction(
+ component, context, AJAX_POLL_FUNCTION);
- /**
- * Methods encodes AJAX script for polling
- *
- * @param context -
- * faces context
- * @param component -
- * component instance
- * @throws IOException -
- * IOException
- */
- public void encodePollScript(FacesContext context, UIComponent component)
- throws IOException {
+ function.addParameter(new JSReference("$('" + clientId
+ + "').component.options"));
+ function.appendScript(script);
- ResponseWriter writer = context.getResponseWriter();
- UIProgressBar progressBar = (UIProgressBar) component;
- String clientId = component.getClientId(context);
- StringBuffer pollScript = new StringBuffer("\n");
- StringBuffer script = new StringBuffer("\n");
- if (isAjaxMode(component) && progressBar.isEnabled()) {
- JSFunction function = AjaxRendererUtils.buildAjaxFunction(
- component, context, AJAX_POLL_FUNCTION);
+ pollScript.append(script);
+ } else {
+ pollScript.append(getStopPollScript(clientId));
+ }
+ pollScript.append(";\n");
+ writer.writeText(pollScript.toString(), null);
+ }
- function.addParameter(new JSReference("$('"
- + clientId + "').component.options"));
- function.appendScript(script);
+ /**
+ * Encodes script for state rendering in client mode
+ *
+ * @param context
+ * @param component
+ * @param state
+ * @throws IOException
+ */
+ public void encodeRenderStateScript(FacesContext context,
+ UIComponent component, String state) throws IOException {
+ ResponseWriter writer = context.getResponseWriter();
+ StringBuffer script = new StringBuffer("\n");
+ script.append(
+ "$('" + component.getClientId(context)
+ + "').component.renderState('").append(state).append(
+ "');");
+ writer.write(script.toString());
+ }
- pollScript.append(script);
- } else {
- pollScript.append(getStopPollScript(clientId));
+ /**
+ * Encodes script for label rendering in client
+ *
+ * @param context
+ * @param component
+ * @throws IOException
+ */
+ public void encodeLabelScript(FacesContext context, UIComponent component)
+ throws IOException {
+ ResponseWriter writer = context.getResponseWriter();
+ StringBuffer script = new StringBuffer("\n");
+ script.append(
+ "$('" + component.getClientId(context)
+ + "').component.renderLabel(").append(
+ getMarkup(context, component)).append(",null);\n");
+ writer.append(script.toString());
+
}
- pollScript.append(";\n");
- writer.writeText(pollScript.toString(), null);
- }
-
-
- /**
- * Encodes script for state rendering in client mode
- * @param context
- * @param component
- * @param state
- * @throws IOException
- */
- public void encodeRenderStateScript (FacesContext context, UIComponent component,
String state) throws IOException {
- ResponseWriter writer = context.getResponseWriter();
- StringBuffer script = new StringBuffer("\n");
- script.append(
- "$('" + component.getClientId(context)
- +
"').component.renderState('").append(state).append("');");
- writer.write(script.toString());
- }
- /**
- * Encodes script for label rendering in client
- *
- * @param context
- * @param component
- * @throws IOException
- */
- public void encodeLabelScript(FacesContext context, UIComponent component)
- throws IOException {
- ResponseWriter writer = context.getResponseWriter();
- StringBuffer script = new StringBuffer("\n");
- script.append(
- "$('" + component.getClientId(context)
- + "').component.renderLabel(").append(
- getMarkup(context, component)).append(",null);\n");
- writer.append(script.toString());
+ /**
+ * Encode initial javascript
+ *
+ * @param context
+ * @param component
+ * @throws IOException
+ */
+ 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);
+ StringBuffer script = new StringBuffer();
+ String clientId = component.getClientId(context);
+ String containerId = ((UIComponent) AjaxRendererUtils
+ .findAjaxContainer(context, component)).getClientId(context);
+ String mode = (String) component.getAttributes().get("mode");
+ UIComponent form = AjaxRendererUtils.getNestingForm(component);
+ String formId = "";
+ if (form != null) {
+ formId = form.getClientId(context);
+ } else if ("ajax".equals(mode)) {
+ // Ignore form absent. It can be rendered by forcing from any
+ // component
+ // throw new FaceletException("Progress bar component in ajax mode
+ // should be placed inside the form");
+ }
+ Number minValue = getNumber(component.getAttributes().get("minValue"));
+ Number maxValue = getNumber(component.getAttributes().get("maxValue"));
+ Number value = (Number) variables.getVariable("value");
+ StringBuffer markup = getMarkup(context, component);
- }
+ script.append("new
ProgressBar('").append(clientId).append("','") // id
+ .append(containerId).append("','") // containerId
+ .append(formId).append("','") // formId
+ .append(mode).append("',") // mode
+ .append(minValue).append(",") // min value
+ .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(
+ "progressVar");
+ if (progressVar != null) {
+ script.append(",'");
+ script.append(progressVar); // progress var
+ script.append("','");
+ } else {
+ script.append(",null,'");
+ }
+ script.append(state);
+ script.append("',");
+ script.append(value.toString());
+ script.append(")\n;");
+ writer.write(script.toString());
+ }
- /**
- * Encode initial javascript
- *
- * @param context
- * @param component
- * @throws IOException
- */
- 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);
- StringBuffer script = new StringBuffer();
- String clientId = component.getClientId(context);
- String containerId = ((UIComponent) AjaxRendererUtils
- .findAjaxContainer(context, component)).getClientId(context);
- String mode = (String) component.getAttributes().get("mode");
- UIComponent form = AjaxRendererUtils.getNestingForm(component);
- String formId = "";
- if (form != null) {
- formId = form.getClientId(context);
- }else if ("ajax".equals(mode)){
- // Ignore form absent. It can be rendered by forcing from any component
- //throw new FaceletException("Progress bar component in ajax mode should be
placed inside the form");
+ /**
+ * Creates options map for AJAX requests
+ *
+ * @param clientId
+ * @param progressBar
+ * @param context
+ * @return
+ */
+ private Map buildAjaxOptions(String clientId, UIProgressBar progressBar,
+ FacesContext context) {
+ Map options = AjaxRendererUtils.buildEventOptions(context, progressBar);
+ Integer interval = new Integer(progressBar.getInterval());
+ options.put("pollId", clientId);
+ options.put("pollinterval", interval);
+ if (progressBar.getAttributes().containsKey("ignoreDupResponses")) {
+ options.put("ignoreDupResponses", progressBar.getAttributes().get(
+ "ignoreDupResponses"));
+ }
+ Map parameters = (Map) options.get("parameters");
+ parameters.put("percent", "percent");
+ parameters.put(clientId, clientId);
+ // options.put("onbeforedomupdate", getOnComplete(clientId, progressBar,
+ // context));
+ return options;
}
- Number minValue = getNumber(component.getAttributes().get("minValue"));
- Number maxValue = getNumber(component.getAttributes().get("maxValue"));
- Number value =(Number)variables.getVariable("value");
- StringBuffer markup = getMarkup(context, component);
-
- script.append("new ProgressBar('")
- .append(clientId).append("','") // id
- .append(containerId).append("','") // containerId
- .append(formId).append("','") // formId
- .append(mode).append("',") // mode
- .append(minValue).append(",") // min value
- .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(
- "progressVar");
- if (progressVar != null) {
- script.append(",'");
- script.append(progressVar); // progress var
- script.append("','");
- } else {
- script.append(",null,'");
- }
- script.append(state);
- script.append("',");
- script.append(value.toString());
- script.append(")\n;");
- writer.write(script.toString());
- }
- /**
- * Creates options map for AJAX requests
- *
- * @param clientId
- * @param progressBar
- * @param context
- * @return
- */
- private Map buildAjaxOptions(String clientId, UIProgressBar progressBar,
- FacesContext context) {
- Map options = AjaxRendererUtils.buildEventOptions(context, progressBar);
- Integer interval = new Integer(progressBar.getInterval());
- options.put("pollId", clientId);
- options.put("pollinterval", interval);
- if (progressBar.getAttributes().containsKey("ignoreDupResponses")) {
- options.put("ignoreDupResponses",
progressBar.getAttributes().get("ignoreDupResponses"));
+ /**
+ * Check if component mode is AJAX
+ *
+ * @param component
+ * @return
+ */
+ private boolean isAjaxMode(UIComponent component) {
+ String mode = (String) component.getAttributes().get("mode");
+ return "ajax".equalsIgnoreCase(mode);
}
- Map parameters = (Map) options.get("parameters");
- parameters.put("percent", "percent");
- parameters.put(clientId, clientId);
-// options.put("onbeforedomupdate", getOnComplete(clientId, progressBar,
-// context));
- return options;
- }
- /**
- * Check if component mode is AJAX
- *
- * @param component
- * @return
- */
- private boolean isAjaxMode(UIComponent component) {
- String mode = (String) component.getAttributes().get("mode");
- return "ajax".equalsIgnoreCase(mode);
- }
-
- /**
- * Encodes client mode
- * @param context
- * @param component
- * @param value
- * @param min
- * @param max
- * @throws IOException
- */
- public void encodeClientMode (FacesContext context, UIComponent component, Number
value, Number min, Number max) throws IOException {
- ResponseWriter writer = context.getResponseWriter();
- String clientId = component.getClientId(context);
- String state = (value.doubleValue() <= min.doubleValue()) ? "initialState"
: ((value.doubleValue() >= max.doubleValue()) ? "completeState" :
"progressState");
- writer.startElement(HTML.DIV_ELEM, component);
- writer.writeAttribute(HTML.id_ATTRIBUTE, clientId , null);
- encodeInitialState(context, component, false);
- encodeProgressState(context, component, false);
- encodeCompletedState(context, component, false);
+ /**
+ * Encodes client mode
+ *
+ * @param context
+ * @param component
+ * @param value
+ * @param min
+ * @param max
+ * @throws IOException
+ */
+ public void encodeClientMode(FacesContext context, UIComponent component,
+ Number value, Number min, Number max) throws IOException {
+ ResponseWriter writer = context.getResponseWriter();
+ String clientId = component.getClientId(context);
+ String state = (value.doubleValue() <= min.doubleValue()) ?
"initialState"
+ : ((value.doubleValue() >= max.doubleValue()) ? "completeState"
+ : "progressState");
+ writer.startElement(HTML.DIV_ELEM, component);
+ writer.writeAttribute(HTML.id_ATTRIBUTE, clientId, null);
+ encodeInitialState(context, component, false);
+ encodeProgressState(context, component, false);
+ encodeCompletedState(context, component, false);
startScript(writer, component);
- encodeInitialScript(context, component, state);
- encodeLabelScript(context, component);
- encodeRenderStateScript(context, component, state);
+ encodeInitialScript(context, component, state);
+ encodeLabelScript(context, component);
+ encodeRenderStateScript(context, component, state);
endScript(writer, component);
- writer.endElement(HTML.DIV_ELEM);
- }
+ writer.endElement(HTML.DIV_ELEM);
+ }
- /**
- * Methods encodes start facet of progress bar component
- *
- * @param context -
- * faces context
- * @param component -
- * component instance
- * @throws IOException -
- * IOException
- */
- public void encodeInitialState(FacesContext context, UIComponent component, boolean
isAjaxMode)
- throws IOException {
- String clientId = component.getClientId(context);
- String initialClass = (String) component.getAttributes().get(
- "initialClass");
- String style = (String) component.getAttributes().get("style");
- ResponseWriter writer = context.getResponseWriter();
- writer.startElement(HTML.DIV_ELEM, component);
- getUtils().writeAttribute(writer, HTML.class_ATTRIBUTE, initialClass);
- getUtils().writeAttribute(writer, "style", style + (!isAjaxMode ?
"display: none" : ""));
- writer.writeAttribute(HTML.id_ATTRIBUTE, (isAjaxMode) ? clientId : clientId +
":initialState", null);
- UIComponent initial = component.getFacet("initial");
- if (initial != null) {
- renderChild(context, initial);
+ /**
+ * Methods encodes start facet of progress bar component
+ *
+ * @param context -
+ * faces context
+ * @param component -
+ * component instance
+ * @throws IOException -
+ * IOException
+ */
+ public void encodeInitialState(FacesContext context, UIComponent component,
+ boolean isAjaxMode) throws IOException {
+ String clientId = component.getClientId(context);
+ String initialClass = (String) component.getAttributes().get(
+ "initialClass");
+ String style = (String) component.getAttributes().get("style");
+ ResponseWriter writer = context.getResponseWriter();
+ writer.startElement(HTML.DIV_ELEM, component);
+ getUtils().writeAttribute(writer, HTML.class_ATTRIBUTE, initialClass);
+ getUtils().writeAttribute(writer, "style",
+ style + (!isAjaxMode ? "display: none" : ""));
+ writer.writeAttribute(HTML.id_ATTRIBUTE, (isAjaxMode) ? clientId
+ : clientId + ":initialState", null);
+ UIComponent initial = component.getFacet("initial");
+ if (initial != null) {
+ renderChild(context, initial);
+ }
+ if (isAjaxMode) {
+ startScript(writer, component);
+ encodeInitialScript(context, component, "initialState");
+ encodePollScript(context, component);
+ endScript(writer, component);
+ }
+ writer.endElement(HTML.DIV_ELEM);
+
}
- if (isAjaxMode) {
- startScript(writer, component);
- encodeInitialScript(context, component,"initialState");
- encodePollScript(context, component);
- endScript(writer, component);
+
+ /**
+ * Encodes progress state of the component
+ *
+ * @param context
+ * @param component
+ * @throws IOException
+ */
+ public void encodeProgressState(FacesContext context,
+ UIComponent component, boolean isAjaxMode) throws IOException {
+ ResponseWriter writer = context.getResponseWriter();
+ ComponentVariables variables = ComponentsVariableResolver.getVariables(
+ this, component);
+ String clientId = component.getClientId(context);
+ String styleClass = (String) variables.getVariable("styleClass");
+ boolean isSimple = isSimpleMarkup(component);
+ String shellClass = (!isSimple) ? "rich-progress-bar-shell-dig "
+ : "rich-progress-bar-shell ";
+ writer.startElement("div", component);
+ getUtils().writeAttribute(
+ writer,
+ "class",
+ "rich-progress-bar-block rich-progress-bar-width " + shellClass
+ + (styleClass != null ? styleClass : ""));
+ getUtils().writeAttribute(writer, HTML.id_ATTRIBUTE,
+ (isAjaxMode) ? clientId : clientId + ":progressState");
+ getUtils().writeAttribute(
+ writer,
+ "style",
+ variables.getVariable("style")
+ + (!isAjaxMode ? "display: none" : ""));
+ encodeProgressBar(context, component, isSimple);
+ if (isAjaxMode) {
+ startScript(writer, component);
+ encodeInitialScript(context, component, "progressState");
+ encodeLabelScript(context, component);
+ encodePollScript(context, component);
+ endScript(writer, component);
+ }
+ writer.endElement("div");
}
- writer.endElement(HTML.DIV_ELEM);
- }
+ /**
+ * Encodes html of component
+ *
+ * @param context -
+ * faces context
+ * @param component -
+ * component instance
+ * @throws IOException
+ */
+ public void encodeProgressBar(FacesContext context, UIComponent component,
+ boolean isSimple) throws IOException {
+ ResponseWriter writer = context.getResponseWriter();
+ String clientId = component.getClientId(context);
+ ComponentVariables variables = ComponentsVariableResolver.getVariables(
+ this, component);
- /**
- * Encodes progress state of the component
- *
- * @param context
- * @param component
- * @throws IOException
- */
- public void encodeProgressState(FacesContext context, UIComponent component, boolean
isAjaxMode)
- throws IOException {
- ResponseWriter writer = context.getResponseWriter();
- ComponentVariables variables = ComponentsVariableResolver.getVariables(
- this, component);
- String clientId = component.getClientId(context);
- String styleClass = (String) variables.getVariable("styleClass");
- boolean isSimple = isSimpleMarkup(component);
- String shellClass = (!isSimple) ? "rich-progress-bar-shell-dig " :
"rich-progress-bar-shell ";
- writer.startElement("div", component);
- getUtils().writeAttribute(
- writer,
- "class",
- "rich-progress-bar-block rich-progress-bar-width " + shellClass
- + (styleClass != null ? styleClass : ""));
- getUtils().writeAttribute(writer, HTML.id_ATTRIBUTE, (isAjaxMode) ? clientId : clientId
+ ":progressState");
- getUtils().writeAttribute(writer, "style",
- variables.getVariable("style") + (!isAjaxMode ? "display: none" :
""));
- encodeProgressBar(context, component, isSimple);
- if (isAjaxMode) {
- startScript(writer, component);
- encodeInitialScript(context, component,"progressState");
- encodeLabelScript(context, component);
- encodePollScript(context, component);
- endScript(writer, component);
- }
- writer.endElement("div");
- }
+ Number value = (Number) variables.getVariable("percent");
- /**
- * Encodes html of component
- *
- * @param context -
- * faces context
- * @param component -
- * component instance
- * @throws IOException
- */
- public void encodeProgressBar(FacesContext context, UIComponent component, boolean
isSimple)
- throws IOException {
- ResponseWriter writer = context.getResponseWriter();
- String clientId = component.getClientId(context);
- ComponentVariables variables = ComponentsVariableResolver.getVariables(
- this, component);
-
- Number value = (Number) variables.getVariable("percent");
+ String width = String.valueOf(value.intValue());
+ String style = (String) component.getAttributes().get("style");
- String width = String.valueOf(value.intValue());
- String style = (String) component.getAttributes().get("style");
+ String completeClass = (String) component.getAttributes().get(
+ "completeClass");
- String completeClass = (String) component.getAttributes().get(
- "completeClass");
+ String remainClass = (String) component.getAttributes().get(
+ "remainClass");
- String remainClass = (String) component.getAttributes().get(
- "remainClass");
-
- if (!isSimple) {
- // <div class='remainClass' id='clientId:remain'
style='style'></div>
- writer.startElement("div", component);
- getUtils().writeAttribute(writer, "class",
- "rich-progress-bar-width rich-progress-bar-remained
rich-progress-bar-padding " + remainClass);
- getUtils().writeAttribute(writer, "id", clientId +
":remain");
- getUtils().writeAttribute(writer, "style", style);
- writer.endElement("div");
-
- // <div class='rich-progress-bar-uploaded-dig'
id='clientId:upload' style='style'>
- writer.startElement("div", component);
- getUtils()
- .writeAttribute(writer, "class",
"rich-progress-bar-uploaded-dig");
- getUtils().writeAttribute(writer, "id", clientId +
":upload");
- getUtils().writeAttribute(writer, "style",
- (style != null ? style + ";" : "") + " width: " +
width + "%;");
-
- // <div class='completeClass' id='clientId:complete'
style='style'></div>
- writer.startElement("div", component);
- getUtils().writeAttribute(writer, "class",
- "rich-progress-bar-height-dig rich-progress-bar-width
rich-progress-bar-completed rich-progress-bar-padding " + completeClass);
- getUtils().writeAttribute(writer, "id", clientId +
":complete");
- getUtils().writeAttribute(writer, "style", style);
- writer.endElement("div");
-
- // </div>
- writer.endElement("div");
- } else {
- writer.startElement("div", component);
- getUtils().writeAttribute(writer, "class",
- "rich-progress-bar-height rich-progress-bar-uploaded " +
completeClass);
- getUtils().writeAttribute(writer, "id", clientId +
":upload");
- getUtils().writeAttribute(writer, "style",
- (style != null ? style + ";" : "") + " width: " +
width + "%;");
- writer.endElement("div");
+ if (!isSimple) {
+ // <div class='remainClass' id='clientId:remain'
+ // style='style'></div>
+ writer.startElement("div", component);
+ getUtils().writeAttribute(
+ writer,
+ "class",
+ "rich-progress-bar-width rich-progress-bar-remained rich-progress-bar-padding
"
+ + remainClass);
+ getUtils().writeAttribute(writer, "id", clientId + ":remain");
+ getUtils().writeAttribute(writer, "style", style);
+ writer.endElement("div");
+
+ // <div class='rich-progress-bar-uploaded-dig'
id='clientId:upload'
+ // style='style'>
+ writer.startElement("div", component);
+ getUtils().writeAttribute(writer, "class",
+ "rich-progress-bar-uploaded-dig");
+ getUtils().writeAttribute(writer, "id", clientId + ":upload");
+ getUtils().writeAttribute(
+ writer,
+ "style",
+ (style != null ? style + ";" : "") + " width: " +
width
+ + "%;");
+
+ // <div class='completeClass' id='clientId:complete'
+ // style='style'></div>
+ writer.startElement("div", component);
+ getUtils()
+ .writeAttribute(
+ writer,
+ "class",
+ "rich-progress-bar-height-dig rich-progress-bar-width
rich-progress-bar-completed rich-progress-bar-padding "
+ + completeClass);
+ getUtils().writeAttribute(writer, "id", clientId + ":complete");
+ getUtils().writeAttribute(writer, "style", style);
+ writer.endElement("div");
+
+ // </div>
+ writer.endElement("div");
+ } else {
+ writer.startElement("div", component);
+ getUtils().writeAttribute(
+ writer,
+ "class",
+ "rich-progress-bar-height rich-progress-bar-uploaded "
+ + completeClass);
+ getUtils().writeAttribute(writer, "id", clientId + ":upload");
+ getUtils().writeAttribute(
+ writer,
+ "style",
+ (style != null ? style + ";" : "") + " width: " +
width
+ + "%;");
+ writer.endElement("div");
+ }
+
}
- }
-
-
- /**
- * Returns parameters attr
- * @param component
- * @param renderer
- * @param percent
- * @return
- */
- public String getParameters(UIComponent component) {
- String parameters = (String) component.getAttributes()
- .get("parameters");
- return parameters;
- }
-
-
- /**
- * Writes start script element
- * @param writer
- * @param component
- * @throws IOException
- */
- private void startScript(ResponseWriter writer, UIComponent component)throws
IOException {
- writer.startElement(HTML.SPAN_ELEM, component);
- writer.writeAttribute(HTML.style_ATTRIBUTE, "display: none;", null);
- writer.startElement(HTML.SCRIPT_ELEM, component);
- }
-
- /**
- * Writes end script element
- * @param writer
- * @param component
- * @throws IOException
- */
- private void endScript(ResponseWriter writer, UIComponent component)throws
IOException {
- writer.endElement(HTML.SCRIPT_ELEM);
- writer.endElement(HTML.SPAN_ELEM);
- }
-
-
- /**
- * 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());
- }else {
- literal = new JSLiteral("null");
+ /**
+ * Returns parameters attr
+ *
+ * @param component
+ * @param renderer
+ * @param percent
+ * @return
+ */
+ public String getParameters(UIComponent component) {
+ String parameters = (String) component.getAttributes()
+ .get("parameters");
+ return parameters;
}
- 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;
- } else {
- if (component.getAttributes().get("label") != null) {
- return false;
- }
+
+ /**
+ * Writes start script element
+ *
+ * @param writer
+ * @param component
+ * @throws IOException
+ */
+ private void startScript(ResponseWriter writer, UIComponent component)
+ throws IOException {
+ writer.startElement(HTML.SPAN_ELEM, component);
+ writer.writeAttribute(HTML.style_ATTRIBUTE, "display: none;", null);
+ writer.startElement(HTML.SCRIPT_ELEM, component);
}
- return true;
- }
- /**
- * Methods encodes finish facet of progress bar component
- *
- * @param context -
- * faces context
- * @param component -
- * component instance
- * @throws IOException -
- * IOException
- */
- public void encodeCompletedState(FacesContext context, UIComponent component, boolean
isAjaxMode)
- throws IOException {
- if (isAjaxMode) {
- Object rerenderAfterComplete = component.getAttributes().get(
- "reRenderAfterComplete");
- Set ajaxRegions = AjaxRendererUtils.asSet(rerenderAfterComplete);
+ /**
+ * Writes end script element
+ *
+ * @param writer
+ * @param component
+ * @throws IOException
+ */
+ private void endScript(ResponseWriter writer, UIComponent component)
+ throws IOException {
+ writer.endElement(HTML.SCRIPT_ELEM);
+ writer.endElement(HTML.SPAN_ELEM);
+ }
- if (ajaxRegions != null) {
- for (Iterator iter = ajaxRegions.iterator(); iter.hasNext();) {
- String id = iter.next().toString();
- AjaxContext ajaxContext = AjaxContext
- .getCurrentInstance(context);
- ajaxContext.addComponentToAjaxRender(component, id);
+ /**
+ * 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());
+ } else {
+ literal = new JSLiteral("null");
}
- }
+ return literal;
}
- String clientId = component.getClientId(context);
- String finishClass = (String) component.getAttributes().get(
- "finishClass");
- String style = (String) component.getAttributes().get("style");
- ResponseWriter writer = context.getResponseWriter();
- writer.startElement(HTML.DIV_ELEM, component);
- writer.writeAttribute(HTML.id_ATTRIBUTE, (isAjaxMode) ? clientId : clientId +
":completeState", null);
- getUtils().writeAttribute(writer, HTML.class_ATTRIBUTE, finishClass);
- getUtils().writeAttribute(writer, "style", style + (!isAjaxMode ?
"display: none" : ""));
- UIComponent completed = component.getFacet("complete");
- if (completed != null) {
- renderChild(context, completed);
+ /**
+ * Return true if component has children components
+ *
+ * @param component
+ * @return
+ */
+ private boolean hasChildren(UIComponent component) {
+ return (component.getChildCount() != 0);
}
- if (isAjaxMode) {
- startScript(writer, component);
- encodeInitialScript(context, component,"completeState");
- writer.write(getStopPollScript(clientId).toString());
- endScript(writer, component);
+
+ /**
+ * Returns true if markup should rendered as simple 2 divs
+ *
+ * @param component
+ * @return
+ */
+ public boolean isSimpleMarkup(UIComponent component) {
+ if (hasChildren(component)) {
+ return false;
+ } else {
+ if (component.getAttributes().get("label") != null) {
+ return false;
+ }
+ }
+ return true;
}
- writer.endElement(HTML.DIV_ELEM);
- }
+ /**
+ * Methods encodes finish facet of progress bar component
+ *
+ * @param context -
+ * faces context
+ * @param component -
+ * component instance
+ * @throws IOException -
+ * IOException
+ */
+ public void encodeCompletedState(FacesContext context,
+ UIComponent component, boolean isAjaxMode) throws IOException {
+ if (isAjaxMode) {
+ Object rerenderAfterComplete = component.getAttributes().get(
+ "reRenderAfterComplete");
+ Set ajaxRegions = AjaxRendererUtils.asSet(rerenderAfterComplete);
- /**
- * Converts value attr to number value
- *
- * @param v -
- * value attr
- * @return result
- */
- public Number getNumber(Object v) {
- Number result = null;
- if (v != null) {
- try {
- if (v instanceof String) {
- result = Double.parseDouble((String) v);
+ if (ajaxRegions != null) {
+ for (Iterator iter = ajaxRegions.iterator(); iter.hasNext();) {
+ String id = iter.next().toString();
+ AjaxContext ajaxContext = AjaxContext
+ .getCurrentInstance(context);
+ ajaxContext.addComponentToAjaxRender(component, id);
+ }
+ }
+ }
+ String clientId = component.getClientId(context);
+ String finishClass = (String) component.getAttributes().get(
+ "finishClass");
+ String style = (String) component.getAttributes().get("style");
+ ResponseWriter writer = context.getResponseWriter();
+ writer.startElement(HTML.DIV_ELEM, component);
+ writer.writeAttribute(HTML.id_ATTRIBUTE, (isAjaxMode) ? clientId
+ : clientId + ":completeState", null);
+ getUtils().writeAttribute(writer, HTML.class_ATTRIBUTE, finishClass);
+ getUtils().writeAttribute(writer, "style",
+ style + (!isAjaxMode ? "display: none" : ""));
+
+ UIComponent completed = component.getFacet("complete");
+ if (completed != null) {
+ renderChild(context, completed);
+ }
+ if (isAjaxMode) {
+ startScript(writer, component);
+ encodeInitialScript(context, component, "completeState");
+ writer.write(getStopPollScript(clientId).toString());
+ endScript(writer, component);
+ }
+ writer.endElement(HTML.DIV_ELEM);
+
+ }
+
+ /**
+ * Converts value attr to number value
+ *
+ * @param v -
+ * value attr
+ * @return result
+ */
+ public Number getNumber(Object v) {
+ Number result = null;
+ if (v != null) {
+ try {
+ if (v instanceof String) {
+ result = Double.parseDouble((String) v);
+ } else {
+ Number n = (Number) v;
+ if (n instanceof BigDecimal || n instanceof Double
+ || n instanceof Float) {
+ result = n.floatValue();
+ } else if (n instanceof Integer || n instanceof Long) {
+ result = n.longValue();
+ }
+ }
+ } catch (Exception e) {
+ // no action
+ }
+ return result;
+ }
+ return new Integer(0);
+ }
+
+ /**
+ * 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 {
- Number n = (Number) v;
- if (n instanceof BigDecimal || n instanceof Double
- || n instanceof Float) {
- result = n.floatValue();
- } else if (n instanceof Integer || n instanceof Long) {
- result = n.longValue();
- }
+ return value;
}
- } catch (Exception e) {
- // no action
- }
}
- return result;
- }
-
- /**
- * 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 {
- return value;
+
+ /**
+ * Returns JS script to stop polling
+ *
+ * @param clientId
+ * @return
+ */
+ private StringBuffer getStopPollScript(String clientId) {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("A4J.AJAX.StopPoll('").append(clientId).append("');\n");
+ return buffer;
}
- }
- /**
- * Returns JS script to stop polling
- *
- * @param clientId
- * @return
- */
- private StringBuffer getStopPollScript(String clientId) {
- StringBuffer buffer = new StringBuffer();
- buffer.append("A4J.AJAX.StopPoll('").append(clientId).append("');\n");
- return buffer;
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.renderkit.RendererBase#getComponentClass()
+ */
+ protected Class getComponentClass() {
+ // only poll component is allowed.
+ return UIProgressBar.class;
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.renderkit.RendererBase#getComponentClass()
- */
- protected Class getComponentClass() {
- // only poll component is allowed.
- return UIProgressBar.class;
- }
+ /*
+ * (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 {
+ ; // We should not render children
+ }
- /*
- * (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 {
- ; // We should not render children
- }
+ /*
+ * (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 {
+ ; // We should not render children
+ }
- /*
- * (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 {
- ; // We should not render children
- }
-
}