diff --git a/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxUtils.java b/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxUtils.java index d9a170164a0..30d686dbcfa 100644 --- a/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxUtils.java +++ b/Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxUtils.java @@ -22,6 +22,7 @@ import er.extensions.appserver.ERXWOContext; import er.extensions.appserver.ajax.ERXAjaxApplication; import er.extensions.appserver.ajax.ERXAjaxSession; +import er.extensions.components.ERXComponentUtilities; import er.extensions.formatters.ERXNumberFormatter; import er.extensions.formatters.ERXTimestampFormatter; import er.extensions.foundation.ERXProperties; @@ -282,14 +283,26 @@ public static void appendScriptFooter(WOResponse response) { response.appendContentString(""); } + /** + * @deprecated use {@link ERXComponentUtilities#hasBinding(String, NSDictionary)} instead + */ + @Deprecated public static boolean hasBinding(String name, NSDictionary associations) { return associations.objectForKey(name) != null; } + /** + * @deprecated use {@link ERXComponentUtilities#bindingNamed(String, NSDictionary)} instead + */ + @Deprecated public static WOAssociation bindingNamed(String name, NSDictionary associations) { return associations.objectForKey(name); } + /** + * @deprecated use {@link ERXComponentUtilities#valueForBinding(String, Object, NSDictionary, WOComponent)} instead + */ + @Deprecated public static Object valueForBinding(String name, Object defaultValue, NSDictionary associations, WOComponent component) { Object value = AjaxUtils.valueForBinding(name, associations, component); if (value != null) { @@ -298,6 +311,10 @@ public static Object valueForBinding(String name, Object defaultValue, NSDiction return defaultValue; } + /** + * @deprecated use {@link ERXComponentUtilities#stringValueForBinding(String, String, NSDictionary, WOComponent)} instead + */ + @Deprecated public static String stringValueForBinding(String name, String defaultValue, NSDictionary associations, WOComponent component) { String value = AjaxUtils.stringValueForBinding(name, associations, component); if (value != null) { @@ -306,6 +323,10 @@ public static String stringValueForBinding(String name, String defaultValue, NSD return defaultValue; } + /** + * @deprecated use {@link ERXComponentUtilities#stringValueForBinding(String, NSDictionary, WOComponent)} instead + */ + @Deprecated public static String stringValueForBinding(String name, NSDictionary associations, WOComponent component) { WOAssociation association = associations.objectForKey(name); if (association != null) { @@ -314,6 +335,10 @@ public static String stringValueForBinding(String name, NSDictionary associations, WOComponent component) { WOAssociation association = associations.objectForKey(name); if (association != null) { @@ -322,6 +347,10 @@ public static Object valueForBinding(String name, NSDictionary associations, WOComponent component) { WOAssociation association = associations.objectForKey(name); if (association != null) { @@ -330,6 +359,10 @@ public static boolean booleanValueForBinding(String name, boolean defaultValue, return defaultValue; } + /** + * @deprecated use {@link ERXComponentUtilities#setValueForBinding(Object, String, NSDictionary, WOComponent)} instead + */ + @Deprecated public static void setValueForBinding(Object value, String name, NSDictionary associations, WOComponent component) { WOAssociation association = associations.objectForKey(name); if (association != null) { diff --git a/Frameworks/Core/ERExtensions/Sources/er/extensions/components/ERXComponentUtilities.java b/Frameworks/Core/ERExtensions/Sources/er/extensions/components/ERXComponentUtilities.java index 7bb43760738..cb86a546d1b 100644 --- a/Frameworks/Core/ERExtensions/Sources/er/extensions/components/ERXComponentUtilities.java +++ b/Frameworks/Core/ERExtensions/Sources/er/extensions/components/ERXComponentUtilities.java @@ -387,4 +387,214 @@ public static T pageWithName(Class componentClass) { return (T) ERXApplication.erxApplication().pageWithName(componentClass); } + /** + * Checks if there is an association for a binding with the given name. + * + * @param name binding name + * @param associations array of associations + * @return true if the association exists + */ + public static boolean hasBinding(String name, NSDictionary associations) { + return associations.objectForKey(name) != null; + } + + /** + * Returns the association for a binding with the given name. If there is + * no such association null will be returned. + * + * @param name binding name + * @param associations array of associations + * @return association for given binding or null + */ + public static WOAssociation bindingNamed(String name, NSDictionary associations) { + return associations.objectForKey(name); + } + + /** + * Checks if the association for a binding with the given name can assign + * values at runtime. + * + * @param name binding name + * @param associations array of associations + * @return true if binding is settable + */ + public static boolean bindingIsSettable(String name, NSDictionary associations) { + boolean isSettable = false; + WOAssociation association = bindingNamed(name, associations); + if (association != null) { + isSettable = association.isValueSettable(); + } + return isSettable; + } + + /** + * Will try to set the given binding in the component to the passed value. + * + * @param value new value for the binding + * @param name binding name + * @param associations array of associations + * @param component component to set the value in + */ + public static void setValueForBinding(Object value, String name, NSDictionary associations, WOComponent component) { + WOAssociation association = bindingNamed(name, associations); + if (association != null) { + association.setValue(value, component); + } + } + + /** + * Retrieves the current value of the given binding from the component. If there + * is no such binding or its value evaluates to null the default + * value will be returned. + * + * @param name binding name + * @param defaultValue default value + * @param associations array of associations + * @param component component to get value from + * @return retrieved value or default value + */ + public static Object valueForBinding(String name, Object defaultValue, NSDictionary associations, WOComponent component) { + Object value = valueForBinding(name, associations, component); + if (value != null) { + return value; + } + return defaultValue; + } + + /** + * Retrieves the current value of the given binding from the component. If there + * is no such binding null will be returned. + * + * @param name binding name + * @param associations array of associations + * @param component component to get value from + * @return retrieved value or null + */ + public static Object valueForBinding(String name, NSDictionary associations, WOComponent component) { + WOAssociation association = bindingNamed(name, associations); + if (association != null) { + return association.valueInComponent(component); + } + return null; + } + + /** + * Retrieves the current string value of the given binding from the component. If there + * is no such binding or its value evaluates to null the default + * value will be returned. + * + * @param name binding name + * @param defaultValue default value + * @param associations array of associations + * @param component component to get value from + * @return retrieved string value or default value + */ + public static String stringValueForBinding(String name, String defaultValue, NSDictionary associations, WOComponent component) { + String value = stringValueForBinding(name, associations, component); + if (value != null) { + return value; + } + return defaultValue; + } + + /** + * Retrieves the current string value of the given binding from the component. If there + * is no such binding null will be returned. + * + * @param name binding name + * @param associations array of associations + * @param component component to get value from + * @return retrieved string value or null + */ + public static String stringValueForBinding(String name, NSDictionary associations, WOComponent component) { + WOAssociation association = bindingNamed(name, associations); + if (association != null) { + return (String) association.valueInComponent(component); + } + return null; + } + + /** + * Retrieves the current boolean value of the given binding from the component. If there + * is no such binding the default value will be returned. + * + * @param name binding name + * @param defaultValue default value + * @param associations array of associations + * @param component component to get value from + * @return retrieved boolean value or default value + */ + public static boolean booleanValueForBinding(String name, boolean defaultValue, NSDictionary associations, WOComponent component) { + WOAssociation association = bindingNamed(name, associations); + if (association != null) { + return association.booleanValueInComponent(component); + } + return defaultValue; + } + + /** + * Retrieves the current boolean value of the given binding from the component. If there + * is no such binding false will be returned. + * + * @param name binding name + * @param associations array of associations + * @param component component to get value from + * @return retrieved boolean value or false + */ + public static boolean booleanValueForBinding(String name, NSDictionary associations, WOComponent component) { + return booleanValueForBinding(name, false, associations, component); + } + + /** + * Retrieves the current int value of the given binding from the component. If there + * is no such binding the default value will be returned. + * + * @param name binding name + * @param defaultValue default value + * @param associations array of associations + * @param component component to get value from + * @return retrieved int value or default value + */ + public static int integerValueForBinding(String name, int defaultValue, NSDictionary associations, WOComponent component) { + WOAssociation association = bindingNamed(name, associations); + if (association != null) { + Object value = association.valueInComponent(component); + return ERXValueUtilities.intValueWithDefault(value, defaultValue); + } + return defaultValue; + } + + + /** + * Retrieves the current array value of the given binding from the component. If there + * is no such binding or its value evaluates to null the default + * value will be returned. + * + * @param name binding name + * @param defaultValue default value + * @param associations array of associations + * @param component component to get value from + * @return retrieved array value or default value + */ + public static NSArray arrayValueForBinding(String name, NSArray defaultValue, NSDictionary associations, WOComponent component) { + WOAssociation association = bindingNamed(name, associations); + if (association != null) { + Object value = association.valueInComponent(component); + return ERXValueUtilities.arrayValueWithDefault(value, defaultValue); + } + return defaultValue; + } + + /** + * Retrieves the current array value of the given binding from the component. If there + * is no such binding null will be returned. + * + * @param name binding name + * @param associations array of associations + * @param component component to get value from + * @return retrieved array value or null + */ + public static NSArray arrayValueForBinding(String name, NSDictionary associations, WOComponent component) { + return arrayValueForBinding(name, null, associations, component); + } }