You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2011/05/10 17:35:37 UTC
svn commit: r1101508 - in
/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago:
internal/util/ComponentAttributeUtils.java util/CreateComponentUtils.java
Author: lofwyr
Date: Tue May 10 15:35:37 2011
New Revision: 1101508
URL: http://svn.apache.org/viewvc?rev=1101508&view=rev
Log:
make independent from UIComponentTag, to support containers with JSP 2.0, but not JSP 2.1 when using Facelets only
Added:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/ComponentAttributeUtils.java
- copied, changed from r1101453, myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/TagUtils.java
Modified:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/CreateComponentUtils.java
Copied: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/ComponentAttributeUtils.java (from r1101453, myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/TagUtils.java)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/ComponentAttributeUtils.java?p2=myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/ComponentAttributeUtils.java&p1=myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/TagUtils.java&r1=1101453&r2=1101508&rev=1101508&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/TagUtils.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/ComponentAttributeUtils.java Tue May 10 15:35:37 2011
@@ -1,4 +1,4 @@
-package org.apache.myfaces.tobago.internal.taglib;
+package org.apache.myfaces.tobago.internal.util;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -17,57 +17,21 @@ package org.apache.myfaces.tobago.intern
* limitations under the License.
*/
-import org.apache.commons.beanutils.PropertyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.myfaces.tobago.component.Attributes;
-import org.apache.myfaces.tobago.component.InputSuggest;
-import org.apache.myfaces.tobago.el.ConstantMethodBinding;
-import org.apache.myfaces.tobago.event.SheetStateChangeSource;
-import org.apache.myfaces.tobago.event.SortActionSource;
-import org.apache.myfaces.tobago.event.TabChangeSource;
-import org.apache.myfaces.tobago.internal.component.AbstractUIMessages;
-import org.apache.myfaces.tobago.internal.component.AbstractUIPage;
-import org.apache.myfaces.tobago.internal.component.AbstractUIPopup;
-import org.apache.myfaces.tobago.util.ComponentUtils;
-
-import javax.faces.application.Application;
-import javax.faces.component.ActionSource;
-import javax.faces.component.EditableValueHolder;
+
import javax.faces.component.UIComponent;
-import javax.faces.component.ValueHolder;
import javax.faces.context.FacesContext;
-import javax.faces.convert.Converter;
-import javax.faces.el.MethodBinding;
import javax.faces.el.ValueBinding;
-import javax.faces.webapp.UIComponentTag;
-import java.lang.reflect.InvocationTargetException;
-public class TagUtils {
- private static final Logger LOG = LoggerFactory.getLogger(TagUtils.class);
+public class ComponentAttributeUtils {
- public static void setIntegerProperty(UIComponent component, String name, String value) {
- if (value != null) {
- if (UIComponentTag.isValueReference(value)) {
- component.setValueBinding(name, createValueBinding(value));
- } else {
- if ((component instanceof AbstractUIPage
- || component instanceof javax.faces.component.UIGraphic
- || component instanceof AbstractUIPopup)
- && (Attributes.WIDTH.equals(name) || Attributes.HEIGHT.equals(name))) {
- if (value.endsWith("px")) {
- value = value.substring(0, value.length() - 2);
- }
- }
- component.getAttributes().put(name, new Integer(value));
- }
- }
- }
+ private static final Logger LOG = LoggerFactory.getLogger(ComponentAttributeUtils.class);
public static void setBooleanProperty(UIComponent component, String name, String value) {
if (value != null) {
- if (UIComponentTag.isValueReference(value)) {
+ if (isValueReference(value)) {
component.setValueBinding(name, createValueBinding(value));
} else {
component.getAttributes().put(name, Boolean.valueOf(value));
@@ -77,7 +41,7 @@ public class TagUtils {
public static void setStringProperty(UIComponent component, String name, String value) {
if (value != null) {
- if (UIComponentTag.isValueReference(value)) {
+ if (isValueReference(value)) {
component.setValueBinding(name, createValueBinding(value));
} else {
component.getAttributes().put(name, value);
@@ -85,138 +49,18 @@ public class TagUtils {
}
}
- public static void setConverterProperty(UIComponent component, String name, String value) {
- if (value != null && component instanceof ValueHolder) {
- final FacesContext facesContext = FacesContext.getCurrentInstance();
- final Application application = facesContext.getApplication();
- if (UIComponentTag.isValueReference(value)) {
- ValueBinding valueBinding = application.createValueBinding(value);
- component.setValueBinding(name, valueBinding);
- } else {
- Converter converter = application.createConverter(value);
- ((ValueHolder) component).setConverter(converter);
- }
- }
- }
-
- public static void setSeverityProperty(UIComponent component, String name, String value) {
- setStringProperty(component, name, value);
- }
-
- public static void setObjectProperty(UIComponent component, String name, String value) {
- setStringProperty(component, name, value);
- }
+ public static boolean isValueReference(String value) {
- public static void setCharacterProperty(UIComponent component, String name, String value) {
- setStringProperty(component, name, value);
+ int start = value.indexOf("#{");
+ if (start < 0) {
+ return false;
+ }
+ int end = value.lastIndexOf('}');
+ return (end >=0 && start < end);
}
public static ValueBinding createValueBinding(String value) {
return FacesContext.getCurrentInstance().getApplication().createValueBinding(value);
}
- public static void setStateChangeListenerMethodBinding(UIComponent component, String value, Class[] args) {
- if (value != null && UIComponentTag.isValueReference(value)) {
- MethodBinding methodBinding = FacesContext.getCurrentInstance().getApplication().createMethodBinding(value, args);
- ((SheetStateChangeSource) component).setStateChangeListener(methodBinding);
- }
- }
-
- public static void setSortActionListenerMethodBinding(UIComponent component, String value, Class[] args) {
- if (value != null && UIComponentTag.isValueReference(value)) {
- MethodBinding methodBinding = FacesContext.getCurrentInstance().getApplication().createMethodBinding(value, args);
- ((SortActionSource) component).setSortActionListener(methodBinding);
- }
- }
-
- public static void setSuggestMethodMethodBinding(UIComponent component, String value, Class[] args) {
- if (value != null && UIComponentTag.isValueReference(value)) {
- MethodBinding methodBinding = FacesContext.getCurrentInstance().getApplication().createMethodBinding(value, args);
- ((InputSuggest) component).setSuggestMethod(methodBinding);
- }
- }
-
- public static void setValueChangeListenerMethodBinding(UIComponent component, String value, Class[] args) {
- if (value != null && UIComponentTag.isValueReference(value)) {
- MethodBinding methodBinding = FacesContext.getCurrentInstance().getApplication().createMethodBinding(value, args);
- ((EditableValueHolder) component).setValueChangeListener(methodBinding);
- }
- }
-
- public static void setValidatorMethodBinding(UIComponent component, String value, Class[] args) {
- if (value != null && UIComponentTag.isValueReference(value)) {
- MethodBinding methodBinding = FacesContext.getCurrentInstance().getApplication().createMethodBinding(value, args);
- ((EditableValueHolder) component).setValidator(methodBinding);
- }
- }
-
- public static void setActionListenerMethodBinding(UIComponent component, String value, Class[] args) {
- if (value != null && UIComponentTag.isValueReference(value)) {
- MethodBinding methodBinding = FacesContext.getCurrentInstance().getApplication().createMethodBinding(value, args);
- ((ActionSource) component).setActionListener(methodBinding);
- }
- }
-
- public static void setActionMethodBinding(UIComponent component, String value, Class[] args) {
- if (value != null) {
- if (UIComponentTag.isValueReference(value)) {
- MethodBinding methodBinding =
- FacesContext.getCurrentInstance().getApplication().createMethodBinding(value, args);
- ((ActionSource) component).setAction(methodBinding);
- } else {
- ((ActionSource) component).setAction(new ConstantMethodBinding(value));
- }
- }
- }
-
- public static void setTabChangeListenerMethodBinding(UIComponent component, String value, Class[] args) {
- if (value != null && UIComponentTag.isValueReference(value)) {
- MethodBinding methodBinding = FacesContext.getCurrentInstance().getApplication().createMethodBinding(value, args);
- ((TabChangeSource) component).setTabChangeListener(methodBinding);
- }
- }
-
- public static void setStringArrayProperty(UIComponent component, String name, String value) {
- if (value != null) {
- if (UIComponentTag.isValueReference(value)) {
- component.setValueBinding(name, createValueBinding(value));
- } else {
- String[] components = ComponentUtils.splitList(value);
- try {
- PropertyUtils.setProperty(component, name, components);
- } catch (IllegalAccessException e) {
- LOG.error("Ignoring Property", e);
- } catch (InvocationTargetException e) {
- LOG.error("Ignoring Property", e);
- } catch (NoSuchMethodException e) {
- LOG.error("Ignoring Property", e);
- }
- }
- }
- }
-
- public static void setValueBindingProperty(UIComponent component, String name, String value) {
- if (value != null && UIComponentTag.isValueReference(value)) {
- ValueBinding valueBinding = createValueBinding(value);
- component.setValueBinding(name, valueBinding);
- }
- }
-
- public static void setOrderByProperty(UIComponent component, String name, String value) {
- if (value != null) {
- if (UIComponentTag.isValueReference(value)) {
- component.setValueBinding(name, createValueBinding(value));
- } else {
- component.getAttributes().put(name, AbstractUIMessages.OrderBy.parse(value));
- }
- }
- }
-
- public static String getValueFromEl(String script) {
- if (UIComponentTag.isValueReference(script)) {
- ValueBinding valueBinding = createValueBinding(script);
- script = (String) valueBinding.getValue(FacesContext.getCurrentInstance());
- }
- return script;
- }
}
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/CreateComponentUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/CreateComponentUtils.java?rev=1101508&r1=1101507&r2=1101508&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/CreateComponentUtils.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/CreateComponentUtils.java Tue May 10 15:35:37 2011
@@ -27,7 +27,7 @@ import org.apache.myfaces.tobago.compone
import org.apache.myfaces.tobago.internal.component.AbstractUIColumn;
import org.apache.myfaces.tobago.internal.component.AbstractUIOut;
import org.apache.myfaces.tobago.internal.component.AbstractUISelectBooleanCheckbox;
-import org.apache.myfaces.tobago.internal.taglib.TagUtils;
+import org.apache.myfaces.tobago.internal.util.ComponentAttributeUtils;
import org.apache.myfaces.tobago.layout.Display;
import org.apache.myfaces.tobago.layout.LayoutManager;
@@ -69,9 +69,9 @@ public class CreateComponentUtils {
public static AbstractUIColumn createTextColumn(
String label, String sortable, String align, String value, String clientId) {
AbstractUIOut text = (AbstractUIOut) createComponent(ComponentTypes.OUT, RendererTypes.OUT, clientId + "_t");
- TagUtils.setStringProperty(text, Attributes.VALUE, value);
- TagUtils.setBooleanProperty(text, Attributes.CREATE_SPAN, "false");
- TagUtils.setBooleanProperty(text, Attributes.ESCAPE, "false");
+ ComponentAttributeUtils.setStringProperty(text, Attributes.VALUE, value);
+ ComponentAttributeUtils.setBooleanProperty(text, Attributes.CREATE_SPAN, "false");
+ ComponentAttributeUtils.setBooleanProperty(text, Attributes.ESCAPE, "false");
text.setDisplay(Display.INLINE);
return createColumn(label, sortable, align, text, clientId);
}
@@ -96,9 +96,9 @@ public class CreateComponentUtils {
public static AbstractUIColumn createColumn(String label, String sortable, String align, String clientId) {
AbstractUIColumn column = (AbstractUIColumn) createComponent(ComponentTypes.COLUMN, null, clientId);
- TagUtils.setStringProperty(column, Attributes.LABEL, label);
- TagUtils.setBooleanProperty(column, Attributes.SORTABLE, sortable);
- TagUtils.setStringProperty(column, Attributes.ALIGN, align);
+ ComponentAttributeUtils.setStringProperty(column, Attributes.LABEL, label);
+ ComponentAttributeUtils.setBooleanProperty(column, Attributes.SORTABLE, sortable);
+ ComponentAttributeUtils.setStringProperty(column, Attributes.ALIGN, align);
return column;
}