Author: abelevich
Date: 2009-08-19 04:20:28 -0400 (Wed, 19 Aug 2009)
New Revision: 15211
Modified:
root/examples/trunk/components/core-demo/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java
root/examples/trunk/components/core-demo/src/main/java/org/ajax4jsf/renderkit/AjaxBeahaviorRenderer.java
Log:
get event name from the ClientBehaviorContext
Modified:
root/examples/trunk/components/core-demo/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java
===================================================================
---
root/examples/trunk/components/core-demo/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java 2009-08-19
08:10:43 UTC (rev 15210)
+++
root/examples/trunk/components/core-demo/src/main/java/org/ajax4jsf/component/behavior/AjaxBehavior.java 2009-08-19
08:20:28 UTC (rev 15211)
@@ -1,10 +1,6 @@
package org.ajax4jsf.component.behavior;
-import java.util.HashMap;
-
-import javax.el.ValueExpression;
import javax.faces.component.behavior.FacesBehavior;
-import javax.faces.context.FacesContext;
/**
* @author Anton Belevich
@@ -14,78 +10,8 @@
public class AjaxBehavior extends javax.faces.component.behavior.AjaxBehavior {
public static final String BEHAVIOR_ID = "org.ajax4jsf.behavior.Ajax";
-
- public static final String EVENT = "event";
-
- private String event;
-
- public String getEvent() {
- if (this.event != null) {
- return this.event;
- }
-
- ValueExpression expression = getValueExpression("event");
-
- if (expression != null) {
- FacesContext ctx = FacesContext.getCurrentInstance();
- return (String)expression.getValue(ctx.getELContext());
- }
-
- return null;
- }
-
- public void setEvent(String event) {
- this.event = event;
- clearInitialState();
- }
-
- @Override
- public Object saveState(FacesContext context) {
-
- Object[] values;
- Object superState = super.saveState(context);
-
- if (initialStateMarked()) {
- if (superState == null) {
- values = null;
- } else {
- values = new Object[] { superState };
- }
- } else {
- values = new Object[2];
- values[0] = superState;
- values[1] = this.event;
- }
- return values;
- }
-
+
@Override
- public void restoreState(FacesContext context, Object state) {
-
- if (state != null) {
-
- Object[] values = (Object[]) state;
- super.restoreState(context, values[0]);
-
- if (values.length != 1) {
- this.event = (String)values[1];
- clearInitialState();
- }
- }
- }
-
-
-
- public void setValueExpression(String name, ValueExpression binding) {
- if(EVENT.equals(name) && binding.isLiteralText()) {
- this.event =
(String)binding.getValue(FacesContext.getCurrentInstance().getELContext());
- clearInitialState();
- } else {
- super.setValueExpression(name, binding);
- }
- }
-
- @Override
public String getRendererType() {
return BEHAVIOR_ID;
}
Modified:
root/examples/trunk/components/core-demo/src/main/java/org/ajax4jsf/renderkit/AjaxBeahaviorRenderer.java
===================================================================
---
root/examples/trunk/components/core-demo/src/main/java/org/ajax4jsf/renderkit/AjaxBeahaviorRenderer.java 2009-08-19
08:10:43 UTC (rev 15210)
+++
root/examples/trunk/components/core-demo/src/main/java/org/ajax4jsf/renderkit/AjaxBeahaviorRenderer.java 2009-08-19
08:20:28 UTC (rev 15211)
@@ -7,7 +7,6 @@
import javax.faces.component.UIComponent;
import javax.faces.component.behavior.ClientBehavior;
import javax.faces.component.behavior.ClientBehaviorContext;
-import javax.faces.component.behavior.ClientBehaviorHolder;
import javax.faces.context.FacesContext;
import javax.faces.render.ClientBehaviorRenderer;
import javax.faces.render.FacesBehaviorRenderer;
@@ -41,29 +40,25 @@
return script;
}
- public String buildAjaxCommand(ClientBehaviorContext behaviorContext, AjaxBehavior
behavior) {
- UIComponent parent = behaviorContext.getComponent();
- FacesContext context = behaviorContext.getFacesContext();
+ public String buildAjaxCommand(ClientBehaviorContext bContext, AjaxBehavior behavior) {
+ UIComponent parent = bContext.getComponent();
+ FacesContext context = bContext.getFacesContext();
JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(parent, context,
"RichFaces.ajax");
-
- Map<String, Object> options = buildOptions(context, behavior, parent);
+
+ Map<String, Object> options = buildOptions(context, bContext);
ajaxFunction.addParameter(options);
return ajaxFunction.toString();
}
- public Map<String, Object> buildOptions(FacesContext context, AjaxBehavior
behavior, UIComponent parent) {
+ public Map<String, Object> buildOptions(FacesContext context,
ClientBehaviorContext bContext) {
+ UIComponent parent = bContext.getComponent();
+ String eventName = bContext.getEventName();
+
Map<String,Object> options = AjaxRendererUtils.buildEventOptions(context,
parent);
- String event = behavior.getEvent();
- if(event == null) {
- ClientBehaviorHolder bHolder = (ClientBehaviorHolder)parent;
- event = bHolder.getDefaultEventName();
- //TODO: if default event name == null (log or throw exception ???)
- }
- options.put(PartialViewContextImpl.BEHAVIOR_EVENT_PARAMETER, event);
- options.put("execute", behavior.getExecute());
- options.put("render", behavior.getExecute());
+ options.put(PartialViewContextImpl.BEHAVIOR_EVENT_PARAMETER, eventName);
+
return options;
}
}