Author: abelevich
Date: 2009-08-13 08:53:44 -0400 (Thu, 13 Aug 2009)
New Revision: 15166
Modified:
root/ui/trunk/components/core/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java
Log:
Modified:
root/ui/trunk/components/core/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java
===================================================================
---
root/ui/trunk/components/core/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java 2009-08-13
12:38:00 UTC (rev 15165)
+++
root/ui/trunk/components/core/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java 2009-08-13
12:53:44 UTC (rev 15166)
@@ -1,13 +1,10 @@
package org.ajax4jsf.component.behavior;
-import java.io.Serializable;
import java.util.Set;
-import javax.el.ELContext;
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
-import javax.faces.component.UIComponentBase;
import javax.faces.component.behavior.ClientBehavior;
import javax.faces.component.behavior.ClientBehaviorContext;
import javax.faces.component.behavior.ClientBehaviorHint;
@@ -15,340 +12,333 @@
import javax.faces.event.BehaviorEvent;
import org.ajax4jsf.Messages;
-import org.ajax4jsf.component.AjaxContainer;
+import org.ajax4jsf.component.AjaxActionComponent;
+import org.ajax4jsf.component.AjaxSupport;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
-import org.ajax4jsf.renderkit.RendererUtils;
+import org.richfaces.util.RichfacesLogger;
+import org.slf4j.Logger;
-public class AjaxBehavior extends UIComponentBase implements ClientBehavior {
+public class AjaxBehavior extends AjaxActionComponent implements ClientBehavior,
AjaxSupport {
- private static final String COMPONENT_FAMILY = "javax.faces.Output";
- public static final String COMPONENT_TYPE = "org.ajax4jsf.AjaxStatus";
+ // ~ Static fields/initializers
+ // ---------------------------------------------
+
+ public static final String COMPONENT_TYPE = "org.ajax4jsf.Support";
+ public static final String COMPONENT_FAMILY = "org.ajax4jsf.AjaxSupport";
+ public static final String DEFAULT_RENDERER_TYPE =
"org.ajax4jsf.components.AjaxSupportRenderer";
+ public static final String AJAX_SUPPORT_SET =
"com.exadel.components.ajax.support.";
-
+ private static final Logger logger = RichfacesLogger.RENDERKIT.getLogger(); // may be
another
+
@Override
- public String getFamily() {
- return COMPONENT_FAMILY;
+ public void setValueExpression(String name, ValueExpression binding) {
+ // var - not allowed name. must be literal.
+ if ("var".equals(name)) {
+ throw new FacesException(Messages.getMessage(
+ Messages.VAR_MUST_BE_LITERAL,
+ getClientId(getFacesContext())));
+ }
+ if ("event".equals(name)) {
+ throw new FacesException(Messages.getMessage(
+ Messages.EVENT_MUST_BE_LITERAL,
+ getClientId(getFacesContext())));
+ }
+ super.setValueExpression(name, binding);
}
/**
- * id of form for wich status will displayed
- *
- */
- private String _for;
-
+ * Create Special <code>ValueBinding</code> for build JavaScrept event
+ * code in parent component from this.
+ *
+ * @return <code>EventValueBinding</code> based on properties of current
+ * component
+ */
+ private ValueExpression getEventValueBinding() {
+ if (logger.isDebugEnabled()) {
+ logger.debug(Messages.getMessage(Messages.CREATE_JAVASCRIPT_EVENT,
+ getId()));
+ }
+
+// return new EventValueExpression(this);
+ return null; //stub!!!
+ }
+
/**
- * @param new value of id of form for wich status will displayed to set
- *
- */
- public void setFor(String _for) {
- this._for = _for;
- }
+ * @return JavaScript eventString. Rebuild on every call, since can be in
+ * loop ( as in dataTable ) with different parameters.
+ */
+ public String getEventString() {
+ StringBuffer buildOnEvent = new StringBuffer();
+ String onsubmit = getOnsubmit();
+ // Insert script to call before submit ajax request.
+ if (null != onsubmit) {
+ buildOnEvent.append(onsubmit).append(";");
+ }
+ buildOnEvent.append(AjaxRendererUtils.buildOnEvent(this,
+ getFacesContext(), getEvent(), true));
+ String script = buildOnEvent.toString();
+ return script;
+ }
- /**
- * @return value or result of valueBinding of id of form for wich status will
displayed
- *
- */
- public String getFor()
- {
- return (String) getValueOrBinding(_for, "for");
- }
-
- /**
- * Text to output on start request
- */
- private String _startText = null;
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.component.UIComponentBase#decode(javax.faces.context.FacesContext)
+ */
+ public void decode(FacesContext context) {
+ // Due to JSF RI 1.1 bug, clear cached clientId
+ setId(getId());
+ super.decode(context);
+ }
- /**
- * setter method for property
- * @param new value of Text to output on start request to set
- */
- public void setStartText(String startText) {
- this._startText = startText;
- }
+ /**
+ * After nornal setting <code>parent</code> property in case of created
+ * component set Ajax properties for parent.
+ *
+ * @see
javax.faces.component.UIComponentBase#setParent(javax.faces.component.UIComponent)
+ */
+ public void setParent(UIComponent parent) {
+ super.setParent(parent);
+ if (null != parent && parent.getFamily() != null) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(Messages.getMessage(Messages.CALLED_SET_PARENT,
+ parent.getClass().getName()));
+ }
+ // TODO If this comopnent configured, set properties for parent
+ // component.
+ // NEW created component have parent, restored view - null in My
+ // faces.
+ // and SUN RI not call at restore saved view.
+ // In other case - set in restoreState method.
+ // if (parent.getParent() != null)
+ {
+ if (logger.isDebugEnabled()) {
+ logger.debug(Messages
+ .getMessage(Messages.DETECT_NEW_COMPONENT));
+ }
+ setParentProperties(parent);
- /**
- * @return value or result of valueBinding of Text to output on start request
- */
- public String getStartText() {
- return (String) getValueOrBinding(_startText, "startText");
- }
-
- /**
- * Text to display on complete request
- */
- private String _stopText = null;
+ }
+ }
+ }
- /**
- * setter method for property
- * @param new value of Text to display on complete request to set
- */
- public void setStopText(String stopText) {
- this._stopText = stopText;
- }
+ public void setParentProperties(UIComponent parent) {
+ ValueExpression valueBinding;
+ if (null != getEvent()) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(Messages.getMessage(
+ Messages.SET_VALUE_BINDING_FOR_EVENT, getEvent()));
+ }
+ // for non action/data components, or for non-default events - build
+ // listener for this instance.
+ valueBinding = getEventValueBinding();
+ parent.setValueExpression(getEvent(), valueBinding);
- /**
- * @return value or result of valueBinding of Text to display on complete request
- */
- public String getStopText() {
- return (String) getValueOrBinding(_stopText, "stopText");
- }
-
- /**
- * Style for display on start request
- */
- private String _startStyle = null;
+ }
+ }
- /**
- * setter method for property
- * @param new value of Style for display on start request to set
- */
- public void setStartStyle(String startStyle) {
- this._startStyle = startStyle;
- }
+ protected UIComponent getSingleComponent() {
+ return getParent();
+ }
- /**
- * @return value or result of valueBinding of Style for display on start request
- */
- public String getStartStyle() {
- return (String) getValueOrBinding(_startStyle, "startStyle");
- }
- /**
- * Style for displaying on complete
- */
- private String _stopStyle = null;
+ public void decode(FacesContext context, UIComponent component) {
+ // TODO Auto-generated method stub
+
+ }
- /**
- * setter method for property
- * @param new value of Style for displaying on complete to set
- */
- public void setStopStyle(String stopStyle) {
- this._stopStyle = stopStyle;
- }
+ public Set<ClientBehaviorHint> getHints() {
+ // TODO Auto-generated method stub
+ return null;
+ }
- /**
- * @return value or result of valueBinding of Style for displaying on complete
- */
- public String getStopStyle() {
- return (String) getValueOrBinding(_stopStyle, "stopStyle");
- }
- /**
- * Style class for display on request
- */
- private String _startStyleClass = null;
+ public String getScript(ClientBehaviorContext behaviorContext) {
+ // TODO Auto-generated method stub
+ return null;
+ }
- /**
- * setter method for property
- * @param new value of Style class for display on request to set
- */
- public void setStartStyleClass(String startStyleClass) {
- this._startStyleClass = startStyleClass;
- }
+ public void broadcast(BehaviorEvent event) {
+ // TODO Auto-generated method stub
+
+ }
- /**
- * @return value or result of valueBinding of Style class for display on request
- */
- public String getStartStyleClass() {
- return (String) getValueOrBinding(_startStyleClass, "startStyleClass");
- }
- /**
- * Style class for display on complete request
- */
- private String _stopStyleClass = null;
+ public Object getData() {
+ // TODO Auto-generated method stub
+ return null;
+ }
- /**
- * setter method for property
- * @param new value of Style class for display on complete request to set
- */
- public void setStopStyleClass(String stopStyleClass) {
- this._stopStyleClass = stopStyleClass;
- }
-
- /**
- * @return value or result of valueBinding of Style class for display on complete
request
- */
- public String getStopStyleClass() {
- return (String) getValueOrBinding(_stopStyleClass, "stopStyleClass");
- }
+ public String getEventsQueue() {
+ // TODO Auto-generated method stub
+ return null;
+ }
- /**
- * Force id to render in Html as is
- */
- private boolean _forceId = false;
- private boolean _forceIdSet = false;
+ public String getFocus() {
+ // TODO Auto-generated method stub
+ return null;
+ }
- /**
- * setter method for property
- * @param new value of Force id to render in Html as is to set
- */
- public void setForceId(boolean forceId) {
- this._forceId = forceId;
- this._forceIdSet = true;
- }
+ public String getOnbeforedomupdate() {
+ // TODO Auto-generated method stub
+ return null;
+ }
- /**
- * @return value or result of valueBinding of Force id to render in Html as is
- */
- public boolean isForceId() {
- return isValueOrBinding(_forceId, _forceIdSet, "forceId");
- }
-
-
-
-
- private String _clientId = null;
+ public String getOncomplete() {
+ // TODO Auto-generated method stub
+ return null;
+ }
- /* (non-Javadoc)
- * @see
javax.faces.component.UIComponentBase#getClientId(javax.faces.context.FacesContext)
- */
- public String getClientId(FacesContext context) {
- if (null == _clientId) {
- String forValue = getFor();
- UIComponent container;
- if (null != forValue) {
- container = RendererUtils.getInstance().findComponentFor(this, forValue);
- // 'for' attribute must be pointed to real container in view tree
- if (null == container || !(container instanceof AjaxContainer)) {
- throw new FacesException(
- Messages.getMessage(Messages.FOR_TARGETS_NO_AJAX_CONTAINER, getId()));
- }
- _clientId = container.getClientId(context) + ":status";
+ public Object getProcess() {
+ // TODO Auto-generated method stub
+ return null;
+ }
- } else if (isForceId()) {
- _clientId = getRenderer(context).convertClientId(context,
- this.getId());
- } else if (null !=(container = (UIComponent)
AjaxRendererUtils.findAjaxContainer(context,this))) {
- _clientId = container.getClientId(context) + ":status";
- } else {
- _clientId = super.getClientId(context);
- }
- }
- return _clientId;
+ public Object getReRender() {
+ // TODO Auto-generated method stub
+ return null;
}
-
- /* (non-Javadoc)
- * reset clientId for calculate
- * @see javax.faces.component.UIComponentBase#setId(java.lang.String)
- */
- public void setId(String arg0) {
- super.setId(arg0);
- _clientId = null;
+ public int getRequestDelay() {
+ // TODO Auto-generated method stub
+ return 0;
}
- /* (non-Javadoc)
- * @see
javax.faces.component.UIComponentBase#restoreState(javax.faces.context.FacesContext,
java.lang.Object)
- */
- public void restoreState(FacesContext context, Object state)
- {
- State myState = (State) state;
- _for = myState._for;
- _startText = myState._startText;
- _stopText = myState._stopText;
- _startStyle = myState._startStyle;
- _stopStyle = myState._stopStyle;
- _startStyleClass = myState._startStyleClass;
- _stopStyleClass = myState._stopStyleClass;
- _forceId = myState._forceId;
- _forceIdSet = myState._forceIdSet;
- super.restoreState(context, myState.superState);
- }
+ public String getSimilarityGroupingId() {
+ // TODO Auto-generated method stub
+ return null;
+ }
- /* (non-Javadoc)
- * @see
javax.faces.component.UIComponentBase#saveState(javax.faces.context.FacesContext)
- */
- public Object saveState(FacesContext context)
- {
- State state = new State();
- state._for = _for;
- state._startText = _startText;
- state._stopText = _stopText;
- state._startStyle = _startStyle;
- state._stopStyle = _stopStyle;
- state._startStyleClass = _startStyleClass;
- state._stopStyleClass = _stopStyleClass;
- state._forceId = _forceId;
- state._forceIdSet = _forceIdSet;
- state.superState = super.saveState(context);
- return state;
- }
-
- /**
- * @author shura (latest modification by $Author: alexsmirnov $)
- * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:25 $
- * Memento pattern state class for save-restore component.
- */
- public static class State implements Serializable {
- /**
- *
- */
- private static final long serialVersionUID = 317266574102385358L;
- Object superState;
- String _for;
- String _startText;
- String _stopText;
- String _startStyle;
- String _stopStyle;
- String _startStyleClass;
- String _stopStyleClass;
- boolean _forceIdSet;
- boolean _forceId;
- }
-
- /**
- * @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, boolean fieldSet, String name){
- if( fieldSet ){
- return field;
- }
- ValueExpression vb = getValueExpression(name);
- if (null != vb) {
- return ((Boolean)vb.getValue(getELContext())).booleanValue();
- } else {
- return false;
- }
+ public String getStatus() {
+ // TODO Auto-generated method stub
+ return null;
+ }
- }
-
- public void decode(FacesContext context, UIComponent component) {
- //TODO should be implemented soon
- }
+ public int getTimeout() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
- public Set<ClientBehaviorHint> getHints() {
- //TODO should be implemented soon
- return null;
- }
+ public boolean isAjaxSingle() {
+ // TODO Auto-generated method stub
+ return false;
+ }
- public String getScript(ClientBehaviorContext behaviorContext) {
- //TODO should be implemented soon
- return null;
- }
+ public boolean isBypassUpdates() {
+ // TODO Auto-generated method stub
+ return false;
+ }
- public void broadcast(BehaviorEvent event) {
- //TODO should be implemented soon
- }
-
- /**
- * @param field - value of field to get.
- * @param name - name of field, to get from ValueBinding
- * @return field or value of binding expression.
- */
- private Object getValueOrBinding(Object field, String name){
- if( null != field){
- return field;
- }
- ValueExpression ve = getValueExpression(name);
- if (null != ve) {
- return ve.getValue(getELContext());
- } else {
- return null;
- }
- }
-
- private ELContext getELContext() {
- return getFacesContext().getELContext();
- }
+ public boolean isIgnoreDupResponses() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+ public boolean isLimitToList() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void setAjaxSingle(boolean single) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setBypassUpdates(boolean bypass) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setData(Object data) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setEventsQueue(String newvalue) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setFocus(String focus) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setIgnoreDupResponses(boolean newvalue) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setLimitToList(boolean submitForm) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setOnbeforedomupdate(String beforeUpdate) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setOncomplete(String oncomplete) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setProcess(Object targetId) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setReRender(Object targetId) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setRequestDelay(int newvalue) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setSimilarityGroupingId(String similarityGroupingId) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setStatus(String status) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setTimeout(int timeout) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public String getEvent() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getOnsubmit() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isDisableDefault() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void setDisableDefault(boolean newvalue) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setEvent(String event) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setOnsubmit(String newOnsubmit) {
+ // TODO Auto-generated method stub
+
+ }
+
}