Author: amarkhel
Date: 2010-05-27 14:18:24 -0400 (Thu, 27 May 2010)
New Revision: 17326
Added:
root/ui/core/trunk/api/src/main/java/org/richfaces/component/AbstractParameter.java
root/ui/core/trunk/api/src/main/java/org/richfaces/component/AbstractPoll.java
root/ui/core/trunk/api/src/main/java/org/richfaces/renderkit/html/AjaxPollRenderer.java
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/AbstractParameterHandler.java
Modified:
root/core/trunk/api/src/main/java/org/ajax4jsf/component/AjaxClientBehavior.java
root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces.js
root/core/trunk/impl/src/main/resources/org/richfaces/renderkit/html/scripts/skinning.js
root/ui/core/trunk/api/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java
root/ui/core/trunk/api/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java
Log:
Implement poll and param components, RF-7653, RF-7982
Modified:
root/core/trunk/api/src/main/java/org/ajax4jsf/component/AjaxClientBehavior.java
===================================================================
---
root/core/trunk/api/src/main/java/org/ajax4jsf/component/AjaxClientBehavior.java 2010-05-27
16:16:11 UTC (rev 17325)
+++
root/core/trunk/api/src/main/java/org/ajax4jsf/component/AjaxClientBehavior.java 2010-05-27
18:18:24 UTC (rev 17326)
@@ -35,10 +35,6 @@
public String getStatus();
- public String getSimilarityGroupingId();
-
- public void setSimilarityGroupingId(String similarityGroupingId);
-
public String getOnevent();
public void setOnevent(String onevent);
Modified: root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces.js
===================================================================
--- root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces.js 2010-05-27
16:16:11 UTC (rev 17325)
+++ root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces.js 2010-05-27
18:18:24 UTC (rev 17326)
@@ -339,6 +339,33 @@
};
//
+ var pollTracker = {};
+ richfaces.startPoll = function(options) {
+ var pollId = options.pollId;
+ var interval = options.pollinterval;
+ var ontimer = options.ontimer;
+ richfaces.stopPoll(pollId);
+
+ richfaces.setZeroRequestDelay(options);
+
+ pollTracker[pollId] = window.setTimeout(function(){
+ var pollElement = document.getElementById(pollId);
+ try {
+ ontimer.call(pollElement || window);
+ richfaces.startPoll(options);
+ } catch (e) {
+ // TODO: handle exception
+ }
+ },interval);
+ };
+
+ richfaces.stopPoll = function(id) {
+ if(pollTracker[id]){
+ window.clearTimeout(pollTracker[id]);
+ delete pollTracker[id];
+ }
+ };
+
var pushTracker = {};
richfaces.startPush = function(options) {
@@ -347,7 +374,8 @@
var pushId = options.pushId;
var interval = options.interval;
var ondataavailable = options.ondataavailable;
-
+ richfaces.setZeroRequestDelay(options);
+
richfaces.stopPush(pushId);
pushTracker[pushId] = setTimeout(function() { // TODO: define this function in
richfaces object to avoid definition every time when call startPush
@@ -449,6 +477,12 @@
}
}
+ richfaces.setZeroRequestDelay = function(options) {
+ if (typeof options.requestDelay == "undefined") {
+ options.requestDelay = 0;
+ }
+ };
+
var getGlobalStatusNameVariable = function() {
return richfaces.statusName;
}
Modified:
root/core/trunk/impl/src/main/resources/org/richfaces/renderkit/html/scripts/skinning.js
===================================================================
---
root/core/trunk/impl/src/main/resources/org/richfaces/renderkit/html/scripts/skinning.js 2010-05-27
16:16:11 UTC (rev 17325)
+++
root/core/trunk/impl/src/main/resources/org/richfaces/renderkit/html/scripts/skinning.js 2010-05-27
18:18:24 UTC (rev 17326)
@@ -1,67 +1,11 @@
-{
- var mediaName = "rich-extended-skinning";
-
+(function(jQuery) {
var userAgent = navigator.userAgent;
-
var skipNavigator = window.opera || (userAgent.indexOf('AppleWebKit/') > -1
&& userAgent.indexOf('Chrome/') == -1);
if (!skipNavigator) {
-
- var resetMedia = function(elt) {
- var media = elt.getAttribute('media');
-
- if (mediaName == media) {
- elt.removeAttribute('media');
- }
+ var f = function() {
+ jQuery("head >
link[media='rich-extended-skinning']").removeAttr('media');
};
-
- if (!window._RICH_FACES_SKINNING_ADDED_TO_BODY) {
- var getElementByTagName = function(elt, name) {
- var elements;
- try {
- elements = elt.selectNodes(".//*[local-name()=\"" +
- name + "\"]");
- } catch (ex) {
- try {
- elements = elt.getElementsByTagName(name);
- } catch (nf) {
- //ok, give up, no elements found
- }
- }
-
- return elements;
- };
-
- var f = function() {
- if (window.RICH_FACES_EXTENDED_SKINNING_ON) {
- var styles = getElementByTagName(document, 'link');
- if (styles) {
- var l = styles.length;
- for (var i = 0; i < l; i++) {
- var elt = styles[i];
- resetMedia(elt);
- }
- }
- }
- };
-
- if (window.addEventListener) {
- window.addEventListener("load", f, false);
- } else {
- window.attachEvent("onload", f);
- }
-
- window._RICH_FACES_SKINNING_ADDED_TO_BODY = true;
- }
-
- if (!window._RICH_FACES_SKINNING_ADDED_TO_AJAX && typeof A4J !=
"undefined" && A4J.AJAX) {
- A4J.AJAX.AddHeadElementTransformer(function (elt) {
- if (window.RICH_FACES_EXTENDED_SKINNING_ON) {
- if (elt.tagName && elt.tagName.toLowerCase() == 'link') {
- resetMedia(elt);
- }
- }
- });
- window._RICH_FACES_SKINNING_ADDED_TO_AJAX = true;
- }
+ jQuery(document).ready(f);
+ f();
}
-};
+}(jQuery));
\ No newline at end of file
Modified:
root/ui/core/trunk/api/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java
===================================================================
---
root/ui/core/trunk/api/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java 2010-05-27
16:16:11 UTC (rev 17325)
+++
root/ui/core/trunk/api/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java 2010-05-27
18:18:24 UTC (rev 17326)
@@ -54,7 +54,7 @@
.of(ClientBehaviorHint.SUBMITTING));
enum PropertyKeys {
- data, execute, onbeforedomupdate, onbegin, oncomplete, onerror, onevent, queueId,
render, similarityGroupingId,
+ data, execute, onbeforedomupdate, onbegin, oncomplete, onerror, onevent, queueId,
render,
status, disabled, limitRender, immediate, bypassUpdates
}
@@ -98,8 +98,6 @@
setOnevent((String) value);
} else if (compare(PropertyKeys.queueId, name)) {
setQueueId((String) value);
- } else if (compare(PropertyKeys.similarityGroupingId, name)) {
- setSimilarityGroupingId((String) value);
} else if (compare(PropertyKeys.status, name)) {
setStatus((String) value);
} else if (compare(PropertyKeys.disabled, name)) {
@@ -231,14 +229,6 @@
getStateHelper().put(PropertyKeys.render, render);
}
- public String getSimilarityGroupingId() {
- return (String) getStateHelper().eval(PropertyKeys.similarityGroupingId);
- }
-
- public void setSimilarityGroupingId(String similarityGroupingId) {
- getStateHelper().put(PropertyKeys.similarityGroupingId, similarityGroupingId);
- }
-
public String getStatus() {
return (String) getStateHelper().eval(PropertyKeys.status);
}
Added:
root/ui/core/trunk/api/src/main/java/org/richfaces/component/AbstractParameter.java
===================================================================
--- root/ui/core/trunk/api/src/main/java/org/richfaces/component/AbstractParameter.java
(rev 0)
+++
root/ui/core/trunk/api/src/main/java/org/richfaces/component/AbstractParameter.java 2010-05-27
18:18:24 UTC (rev 17326)
@@ -0,0 +1,260 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.component;
+
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.component.UIComponentBase;
+import javax.faces.component.UIParameter;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.ActionListener;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.component.JavaScriptParameter;
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.cdk.annotations.TagType;
+
+/**
+ * @author shura (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.2 $ $Date: 2007/02/01 15:31:55 $
+ *
+ */
+@JsfComponent(tag = @Tag(name = "param", handler =
"org.richfaces.view.facelets.html.AbstractParameterHandler",
+
+generate = false, type = TagType.Facelets))
+public class AbstractParameter extends UIParameter implements ActionListener,
+ JavaScriptParameter {
+ public static final String COMPONENT_TYPE = "org.richfaces.UIParameter";
+ private static String noEscapeAttr = "noEscape";
+
+ /** ********************************************************* */
+
+ /**
+ * Binding for update on ActionEvent
+ */
+ private ValueExpression assignToBinding = null;
+
+ /** ********************************************************* */
+
+ /**
+ * Converter for update value with this parameter
+ */
+ private Converter converter = null;
+
+ /** ********************************************************* */
+
+ /**
+ * Skip quota escaping of parameter value - for substitute JavaScript
+ * exspression on submit
+ */
+ private Boolean noEscape = null;
+
+ public void setAssignToBinding(ValueExpression propertyBinding) {
+ this.assignToBinding = propertyBinding;
+ }
+
+ public ValueExpression getAssignToBinding() {
+ return assignToBinding;
+ }
+
+ public void setConverter(Converter converter) {
+ this.converter = converter;
+ }
+
+ public Converter getConverter() {
+ return converter;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.framework.ajax.JavaScriptParameter#setNoEscape(boolean)
+ */
+ public void setNoEscape(boolean noEscape) {
+ this.noEscape = Boolean.valueOf(noEscape);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.framework.ajax.JavaScriptParameter#isNoEscape()
+ */
+ public boolean isNoEscape() {
+ return isValueOrBinding(noEscape, noEscapeAttr);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.event.ActionListener#processAction(javax.faces.event.ActionEvent)
+ */
+ public void processAction(ActionEvent actionEvent)
+ throws AbortProcessingException {
+ FacesContext context = getFacesContext();
+ ELContext elContext = context.getELContext();
+ ValueExpression updateBinding = getAssignToBinding();
+
+ if (updateBinding != null && (!updateBinding.isReadOnly(elContext))) {
+ Object requestValue = context.getExternalContext()
+ .getRequestParameterMap().get(getName());
+
+ if (requestValue != null && requestValue instanceof String) {
+ Class<?> type = updateBinding.getType(elContext);
+ Converter converter = createConverter(context, type);
+
+ if (null != converter) {
+ requestValue = converter.getAsObject(context, this,
+ (String) requestValue);
+ }
+ }
+
+ if (null != requestValue) {
+ updateBinding.setValue(elContext, requestValue);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.component.UIParameter#getName()
+ */
+ public String getName() {
+ String name = super.getName();
+
+ // If name not set - use clientId. be Careful !
+ if (null == name) {
+ name = getClientId(FacesContext.getCurrentInstance());
+ }
+
+ return name;
+ }
+
+ public Object getValue() {
+ Object value = super.getValue();
+
+ // TODO - perform conversion if converter is present.
+ if (null != value) {
+ Class<?> type = value.getClass();
+ FacesContext context = getFacesContext();
+ Converter converter = createConverter(context, type);
+
+ if (null != converter) {
+ value = converter.getAsString(context, this, value);
+ }
+ }
+
+ return value;
+ }
+
+ /** ********************************************************* */
+
+ /**
+ * @param context
+ * @param type
+ * @return
+ * @throws FacesException
+ */
+ private Converter createConverter(FacesContext context, Class<?> type)
+ throws FacesException {
+ Converter converter = getConverter();
+
+ if (converter == null && type != null && !type.equals(String.class)
+ && !type.equals(Object.class)) {
+ try {
+ converter = context.getApplication().createConverter(type);
+ } catch (Exception e) {
+ throw new FacesException(Messages.getMessage(
+ Messages.NO_CONVERTER_REGISTERED, type.getName()), e);
+ }
+ }
+
+ return converter;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.component.UIComponentBase#restoreState(javax.faces.context.FacesContext)
+ */
+ @Override
+ public void restoreState(FacesContext context, Object state) {
+ Object[] values = (Object[]) state;
+
+ super.restoreState(context, values[0]);
+
+ // restore fields values
+ assignToBinding = (ValueExpression) UIComponentBase
+ .restoreAttachedState(context, values[1]);
+ noEscape = (Boolean) values[2];
+ converter = (Converter) UIComponentBase.restoreAttachedState(context,
+ values[3]);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.component.UIComponentBase#saveState(javax.faces.context.FacesContext)
+ */
+ @Override
+ public Object saveState(FacesContext context) {
+ Object[] values = new Object[5];
+
+ values[0] = super.saveState(context);
+
+ // save fields values
+ values[1] = UIComponentBase.saveAttachedState(context, assignToBinding);
+ values[2] = noEscape;
+ values[3] = UIComponentBase.saveAttachedState(context, converter);
+
+ return values;
+ }
+
+ /**
+ * @param field -
+ * value of field to get.
+ * @param name -
+ * name of field, to get from ValueBinding
+ * @return boolean value, based on field or valuebinding.
+ */
+ private boolean isValueOrBinding(Boolean field, String name) {
+ if (null != field) {
+ return field.booleanValue();
+ }
+
+ ValueExpression vb = getValueExpression(name);
+
+ if (null != vb) {
+ FacesContext context = getFacesContext();
+ ELContext elContext = context.getELContext();
+
+ return ((Boolean) vb.getValue(elContext)).booleanValue();
+ } else {
+ return false;
+ }
+ }
+}
Added: root/ui/core/trunk/api/src/main/java/org/richfaces/component/AbstractPoll.java
===================================================================
--- root/ui/core/trunk/api/src/main/java/org/richfaces/component/AbstractPoll.java
(rev 0)
+++
root/ui/core/trunk/api/src/main/java/org/richfaces/component/AbstractPoll.java 2010-05-27
18:18:24 UTC (rev 17326)
@@ -0,0 +1,69 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+
+package org.richfaces.component;
+
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.EventName;
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.cdk.annotations.TagType;
+
+import javax.faces.component.UICommand;
+
+/**
+ * Component for periodically call AJAX events on server ( poll actions )
+ * @author shura
+ *
+ */
+@JsfComponent(
+ tag = @Tag(generate = true, handler =
"org.richfaces.view.facelets.html.AjaxPollHandler", type = TagType.Facelets)
+ )
+public abstract class AbstractPoll extends UICommand {
+ public static final String COMPONENT_TYPE = "org.richfaces.Poll";
+
+ public static final String COMPONENT_FAMILY = "org.richfaces.Poll";
+
+ public static final String TIMER = "timer";
+
+ public static final String ON_TIMER = "ontimer";
+
+ @Attribute(defaultValue = "1000")
+ public abstract int getInterval();
+
+ @Attribute(defaultValue = "true")
+ public abstract boolean isEnabled();
+
+ @Attribute(events = @EventName("begin"))
+ public abstract String getOnbegin();
+
+ @Attribute(events = @EventName("beforedomupdate"))
+ public abstract String getOnbeforedomupdate();
+
+ @Attribute(events = @EventName("complete"))
+ public abstract String getOncomplete();
+
+ @Attribute(events = @EventName(value = TIMER, defaultEvent = true))
+ public abstract String getOntimer();
+
+}
\ No newline at end of file
Added:
root/ui/core/trunk/api/src/main/java/org/richfaces/renderkit/html/AjaxPollRenderer.java
===================================================================
---
root/ui/core/trunk/api/src/main/java/org/richfaces/renderkit/html/AjaxPollRenderer.java
(rev 0)
+++
root/ui/core/trunk/api/src/main/java/org/richfaces/renderkit/html/AjaxPollRenderer.java 2010-05-27
18:18:24 UTC (rev 17326)
@@ -0,0 +1,139 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.renderkit.html;
+
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.JSFunctionDefinition;
+import org.ajax4jsf.javascript.JSReference;
+import org.ajax4jsf.renderkit.AjaxEventOptions;
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.renderkit.HandlersChain;
+import org.ajax4jsf.renderkit.RendererBase;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.component.AbstractPoll;
+
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.event.ActionEvent;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author shura
+ */
+@ResourceDependencies(value = {
+ @ResourceDependency(library = "javax.faces", name = "jsf.js"),
+ @ResourceDependency(name = "jquery.js"),
+ @ResourceDependency(name = "richfaces.js") })
+@JsfRenderer
+public class AjaxPollRenderer extends RendererBase {
+
+ public static final String COMPONENT_FAMILY = "org.richfaces.Poll";
+
+ public static final String RENDERER_TYPE = "org.richfaces.PollRenderer";
+ private static final String AJAX_POLL_FUNCTION = "RichFaces.startPoll";
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.renderkit.RendererBase#doEncodeEnd(javax.faces.context.ResponseWriter,
+ * javax.faces.context.FacesContext, javax.faces.component.UIComponent)
+ */
+ protected void doEncodeEnd(ResponseWriter writer, FacesContext context,
+ UIComponent component) throws IOException {
+ AbstractPoll poll = (AbstractPoll) component;
+ writer.startElement(HTML.SPAN_ELEM, component);
+ writer.writeAttribute(HTML.STYLE_ATTRIBUTE, "display:none;", null);
+ getUtils().encodeId(context, component);
+ getUtils().encodeBeginFormIfNessesary(context, component);
+ // polling script.
+ writer.startElement(HTML.SCRIPT_ELEM, component);
+ writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
+ StringBuffer script = new StringBuffer("\n");
+ if (poll.isEnabled()) {
+ JSFunction function = new JSFunction(AJAX_POLL_FUNCTION);
+ Map<String, Object> options = new HashMap<String, Object>();
+ Integer interval = new Integer(poll.getInterval());
+ options.put("pollinterval", interval);
+ options.put("pollId", component.getClientId(context));
+ HandlersChain handlersChain = new HandlersChain(poll);
+ handlersChain.addInlineHandlerFromAttribute(context, AbstractPoll.ON_TIMER);
+ handlersChain.addBehaviors(context, AbstractPoll.TIMER);
+
+ if (!handlersChain.hasSubmittingBehavior()) {
+ JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(
+ context, poll, AjaxRendererUtils.AJAX_FUNCTION_NAME);
+ AjaxEventOptions eventOptions = AjaxRendererUtils.buildEventOptions(context, poll);
+ if (!eventOptions.isEmpty()) {
+ ajaxFunction.addParameter(eventOptions);
+ }
+ handlersChain.addInlineHandlerAsValue(context, ajaxFunction.toScript());
+ }
+
+ String handler = handlersChain.toScript();
+
+ if (handler != null) {
+ JSFunctionDefinition timerHandler = new JSFunctionDefinition(JSReference.EVENT);
+ timerHandler.addToBody(handler);
+ options.put(AbstractPoll.ON_TIMER,timerHandler);
+ }
+ function.addParameter(options);
+ function.appendScript(script);
+ } else {
+ script.append("RichFaces.stopPoll('").append(component.getClientId(context)).append("')");
+ }
+ script.append(";\n");
+ writer.writeText(script.toString(), null);
+ writer.endElement(HTML.SCRIPT_ELEM);
+ getUtils().encodeEndFormIfNessesary(context, component);
+ writer.endElement(HTML.SPAN_ELEM);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.renderkit.RendererBase#getComponentClass()
+ */
+ protected Class<? extends UIComponent> getComponentClass() {
+ // only push component is allowed.
+ return AbstractPoll.class;
+ }
+
+ @Override
+ protected void doDecode(FacesContext context, UIComponent component) {
+ super.doDecode(context, component);
+
+ AbstractPoll poll = (AbstractPoll) component;
+ if (poll.isEnabled()) {
+ Map<String, String> requestParameterMap =
context.getExternalContext().getRequestParameterMap();
+ if (requestParameterMap.get(poll.getClientId(context)) != null) {
+ new ActionEvent(poll).queue();
+ }
+ }
+ }
+
+}
Modified:
root/ui/core/trunk/api/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java
===================================================================
---
root/ui/core/trunk/api/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java 2010-05-27
16:16:11 UTC (rev 17325)
+++
root/ui/core/trunk/api/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java 2010-05-27
18:18:24 UTC (rev 17326)
@@ -60,17 +60,10 @@
public static final String PUSH_INTERVAL_PARAMETER =
"A4J.AJAX.Push.INTERVAL";
- public static final String PUSH_WAIT_PARAMETER = "A4J.AJAX.Push.WAIT";
-
- @Deprecated
- public static final String PUSH_URL_PARAMETER = "A4J.AJAX.Push.URL";
-
public static final int DEFAULT_PUSH_INTERVAL = 1000;
public static final int DEFAULT_PUSH_WAIT = Integer.MIN_VALUE;
- private static final String AJAX_PUSH_FUNCTION = "A4J.AJAX.Push";
-
/* (non-Javadoc)
* @see
org.ajax4jsf.renderkit.RendererBase#doEncodeEnd(javax.faces.context.ResponseWriter,
* javax.faces.context.FacesContext, javax.faces.component.UIComponent)
Added:
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/AbstractParameterHandler.java
===================================================================
---
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/AbstractParameterHandler.java
(rev 0)
+++
root/ui/core/trunk/api/src/main/java/org/richfaces/view/facelets/html/AbstractParameterHandler.java 2010-05-27
18:18:24 UTC (rev 17326)
@@ -0,0 +1,172 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.view.facelets.html;
+
+import javax.faces.component.ActionSource;
+import javax.faces.component.UIComponent;
+import javax.faces.convert.Converter;
+import javax.faces.view.facelets.ComponentConfig;
+import javax.faces.view.facelets.ComponentHandler;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.MetaRule;
+import javax.faces.view.facelets.MetaRuleset;
+import javax.faces.view.facelets.Metadata;
+import javax.faces.view.facelets.MetadataTarget;
+import javax.faces.view.facelets.TagAttribute;
+import javax.faces.view.facelets.TagAttributeException;
+
+import org.ajax4jsf.Messages;
+import org.richfaces.component.AbstractParameter;
+
+/**
+ * @author shura (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2007/02/01 15:31:23 $
+ *
+ */
+public class AbstractParameterHandler extends ComponentHandler {
+
+ /**
+ * @author shura (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2007/02/01 15:31:23 $
+ *
+ */
+ public static class ActionParamMetaRule extends MetaRule {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.tag.SuggestionHandler.SuggestionMetaRule#applyRule(java.lang.String,
+ * com.sun.facelets.tag.TagAttribute,
+ * com.sun.facelets.tag.MetadataTarget)
+ */
+ public Metadata applyRule(String name, TagAttribute attribute,
+ MetadataTarget meta) {
+ if (meta.isTargetInstanceOf(AbstractParameter.class)) {
+ if ("assignTo".equals(name)) {
+ return new AssignToValueBindingMetadata(attribute);
+ } else if ("converter".equals(name)) {
+ if (attribute.isLiteral()) {
+ return new LiteralConverterMetadata(attribute
+ .getValue());
+ } else {
+ return new DynamicConverterMetadata(attribute);
+ }
+
+ }
+ }
+
+ return null;
+ }
+
+ }
+
+ final static class LiteralConverterMetadata extends Metadata {
+
+ private final String converterId;
+
+ public LiteralConverterMetadata(String converterId) {
+ this.converterId = converterId;
+ }
+
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ ((AbstractParameter) instance).setConverter(ctx.getFacesContext()
+ .getApplication().createConverter(this.converterId));
+ }
+ }
+
+ final static class DynamicConverterMetadata extends Metadata {
+
+ private final TagAttribute attr;
+
+ public DynamicConverterMetadata(TagAttribute attr) {
+ this.attr = attr;
+ }
+
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ ((AbstractParameter) instance).setConverter((Converter) this.attr
+ .getObject(ctx, Converter.class));
+ }
+ }
+
+ final static class AssignToValueBindingMetadata extends Metadata {
+
+ private final TagAttribute attr;
+
+ public AssignToValueBindingMetadata(TagAttribute attr) {
+ this.attr = attr;
+ }
+
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ ((AbstractParameter) instance).setAssignToBinding(attr
+ .getValueExpression(ctx, Object.class));
+ }
+ }
+
+ private TagAttribute _assignTo;
+ private TagAttribute _converter;
+
+ /**
+ * @param config
+ */
+ public AbstractParameterHandler(ComponentConfig config) {
+ super(config);
+ _assignTo = getAttribute("assignTo");
+ _converter = getAttribute("converter");
+
+ if (null != _assignTo) {
+ if (_assignTo.isLiteral()) {
+ throw new TagAttributeException(this.tag, this._assignTo,
+ Messages.getMessage(Messages.MUST_BE_EXPRESSION_ERROR));
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.sun.facelets.FaceletHandler#apply(com.sun.facelets.FaceletContext,
+ * javax.faces.component.UIComponent)
+ */
+ public void onComponentCreated(FaceletContext ctx, UIComponent c,
+ UIComponent parent) {
+ if (parent instanceof ActionSource) {
+ if (_assignTo != null) {
+ AbstractParameter al = (AbstractParameter) c;
+ ((ActionSource) parent).addActionListener(al);
+ }
+ }
+ }
+
+ private static final ActionParamMetaRule actionParamMetaRule = new
ActionParamMetaRule();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.tag.AjaxComponentHandler#createMetaRuleset(java.lang.Class)
+ */
+ protected MetaRuleset createMetaRuleset(Class type) {
+ MetaRuleset metaRules = super.createMetaRuleset(type);
+ metaRules.addRule(actionParamMetaRule);
+ return metaRules;
+ }
+
+}