Author: nbelaevski
Date: 2010-05-25 14:10:36 -0400 (Tue, 25 May 2010)
New Revision: 17237
Added:
root/ui-sandbox/core/trunk/src/main/java/org/ajax4jsf/component/EventValueBinding.java
root/ui-sandbox/core/trunk/src/main/java/org/ajax4jsf/component/EventValueExpression.java
Log:
https://jira.jboss.org/browse/RF-8682
Copied:
root/ui-sandbox/core/trunk/src/main/java/org/ajax4jsf/component/EventValueBinding.java
(from rev 17230,
root/core/trunk/impl/src/main/java/org/ajax4jsf/component/EventValueBinding.java)
===================================================================
---
root/ui-sandbox/core/trunk/src/main/java/org/ajax4jsf/component/EventValueBinding.java
(rev 0)
+++
root/ui-sandbox/core/trunk/src/main/java/org/ajax4jsf/component/EventValueBinding.java 2010-05-25
18:10:36 UTC (rev 17237)
@@ -0,0 +1,197 @@
+/**
+ * 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.ajax4jsf.component;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.PropertyNotFoundException;
+import javax.faces.el.ValueBinding;
+
+/**
+ * Inner class for build event string for parent component.
+ *
+ * @author shura (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:57:38 $ Disadvantages -
+ * not rebuild event string setted as EL expression. TODO - save
+ * expressions for build event string at render phase.
+ */
+public class EventValueBinding extends ValueBinding implements StateHolder {
+ private static final long serialVersionUID = -6583167387542332290L;
+
+ /**
+ * current update component. transient since saved state as component.
+ */
+ private transient AjaxSupport component = null;
+ private String componentId;
+
+ /**
+ * Default constructor for restoreState.
+ */
+ public EventValueBinding() {
+ }
+
+ /**
+ * Constructor for build from AjaxComponent.
+ *
+ * @param update
+ */
+ public EventValueBinding(AjaxSupport update) {
+ component = update;
+
+ // _componentId = string;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.el.ValueBinding#getType(javax.faces.context.FacesContext)
+ */
+ @Override
+ public Class getType(FacesContext facesContext) throws EvaluationException,
PropertyNotFoundException {
+ return String.class;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.el.ValueBinding#getValue(javax.faces.context.FacesContext)
+ */
+ @Override
+ public Object getValue(FacesContext facesContext) throws EvaluationException,
PropertyNotFoundException {
+ if (((UIComponent) getComponent(facesContext)).isRendered()) {
+ return getComponent(facesContext).getEventString();
+ } else {
+ return null;
+ }
+ }
+
+ private AjaxSupport getComponent(FacesContext facesContext) throws
EvaluationException {
+ if (component == null) {
+ UIComponent uiComponent =
facesContext.getViewRoot().findComponent(componentId);
+
+ if ((null != uiComponent) && (uiComponent instanceof AjaxSupport)) {
+ component = (AjaxSupport) uiComponent;
+ } else {
+ throw new
EvaluationException(Messages.getMessage(Messages.COMPONENT_NOT_FOUND, componentId));
+ }
+ }
+
+ return component;
+ }
+
+ /**
+ * @param component the component to set
+ */
+ public void setComponent(AjaxSupport component) {
+ this.component = component;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.el.ValueBinding#isReadOnly(javax.faces.context.FacesContext)
+ */
+ @Override
+ public boolean isReadOnly(FacesContext facesContext) throws EvaluationException,
PropertyNotFoundException {
+
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.el.ValueBinding#setValue(javax.faces.context.FacesContext,
+ * java.lang.Object)
+ */
+ @Override
+ public void setValue(FacesContext facesContext, Object value)
+ throws EvaluationException, PropertyNotFoundException {
+
+ throw new EvaluationException(Messages.getMessage(Messages.EVENT_IS_READ_ONLY));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
+ */
+ public Object saveState(FacesContext context) {
+ if (null == component) {
+ return componentId;
+ } else {
+ return AjaxRendererUtils.getAbsoluteId((UIComponent) getComponent(context));
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext,
+ * java.lang.Object)
+ */
+ public void restoreState(FacesContext context, Object state) {
+
+ // TODO Auto-generated method stub
+ componentId = (String) state;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.component.StateHolder#isTransient()
+ */
+ public boolean isTransient() {
+
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.component.StateHolder#setTransient(boolean)
+ */
+ public void setTransient(boolean newTransientValue) {
+
+ // TODO Auto-generated method stub
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.el.ValueBinding#getExpressionString()
+ */
+ @Override
+ public String getExpressionString() {
+
+ // FacesContext context = FacesContext.getCurrentInstance();
+ // UIComponent component = (UIComponent) getComponent(context);
+ // return
"#{ajaxSupport["+component.getClientId(context)+"]}";
+ return null;
+ }
+}
Copied:
root/ui-sandbox/core/trunk/src/main/java/org/ajax4jsf/component/EventValueExpression.java
(from rev 17230,
root/core/trunk/impl/src/main/java/org/ajax4jsf/component/EventValueExpression.java)
===================================================================
---
root/ui-sandbox/core/trunk/src/main/java/org/ajax4jsf/component/EventValueExpression.java
(rev 0)
+++
root/ui-sandbox/core/trunk/src/main/java/org/ajax4jsf/component/EventValueExpression.java 2010-05-25
18:10:36 UTC (rev 17237)
@@ -0,0 +1,207 @@
+/**
+ * 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.ajax4jsf.component;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ValueExpression;
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Maksim Kaszynski
+ */
+public class EventValueExpression extends ValueExpression implements StateHolder {
+ private static final long serialVersionUID = -6583167387542332290L;
+
+ /**
+ * current update component. transient since saved state as component.
+ */
+ private transient AjaxSupport component = null;
+ private String componentId;
+
+ public EventValueExpression() {
+
+ // TODO Auto-generated constructor stub
+ }
+
+ public EventValueExpression(AjaxSupport component) {
+ super();
+ this.component = component;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.Expression#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ private AjaxSupport getComponent(FacesContext facesContext) throws ELException {
+ if (component == null) {
+ UIComponent uiComponent =
facesContext.getViewRoot().findComponent(componentId);
+
+ if ((null != uiComponent) && (uiComponent instanceof AjaxSupport)) {
+ component = (AjaxSupport) uiComponent;
+ } else {
+ throw new ELException(Messages.getMessage(Messages.COMPONENT_NOT_FOUND,
componentId));
+ }
+ }
+
+ return component;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.ValueExpression#getExpectedType()
+ */
+ @Override
+ public Class<?> getExpectedType() {
+ return String.class;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.Expression#getExpressionString()
+ */
+ @Override
+ public String getExpressionString() {
+
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.ValueExpression#getType(javax.el.ELContext)
+ */
+ @Override
+ public Class<?> getType(ELContext context) {
+ return String.class;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.ValueExpression#getValue(javax.el.ELContext)
+ */
+ @Override
+ public Object getValue(ELContext context) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ AjaxSupport component = getComponent(facesContext);
+
+ if (((UIComponent) component).isRendered()) {
+ return component.getEventString();
+ } else {
+ return null;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.Expression#hashCode()
+ */
+ @Override
+ public int hashCode() {
+
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.Expression#isLiteralText()
+ */
+ @Override
+ public boolean isLiteralText() {
+
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.ValueExpression#isReadOnly(javax.el.ELContext)
+ */
+ @Override
+ public boolean isReadOnly(ELContext context) {
+ return true;
+ }
+
+ public boolean isTransient() {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext,
+ * java.lang.Object)
+ */
+ public void restoreState(FacesContext context, Object state) {
+ componentId = (String) state;
+ }
+
+ public Object saveState(FacesContext context) {
+ if (null == component) {
+ return componentId;
+ } else {
+ return AjaxRendererUtils.getAbsoluteId((UIComponent) getComponent(context));
+ }
+ }
+
+ /**
+ * @param component the component to set
+ */
+ public void setComponent(AjaxSupport component) {
+ this.component = component;
+ }
+
+ public void setTransient(boolean newTransientValue) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.ValueExpression#setValue(javax.el.ELContext,
+ * java.lang.Object)
+ */
+ @Override
+ public void setValue(ELContext context, Object value) {
+ throw new ELException(Messages.getMessage(Messages.EVENT_IS_READ_ONLY));
+ }
+}