You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2016/04/05 09:43:17 UTC

wicket git commit: Minor improvements to Behavior#onAttribute()

Repository: wicket
Updated Branches:
  refs/heads/master 4aa35949a -> c3b845c75


Minor improvements to Behavior#onAttribute()


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/c3b845c7
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/c3b845c7
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/c3b845c7

Branch: refs/heads/master
Commit: c3b845c7543aea2425f3436ea2850ce7ba0f377c
Parents: 4aa3594
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Tue Apr 5 09:42:49 2016 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Tue Apr 5 09:42:49 2016 +0200

----------------------------------------------------------------------
 .../org/apache/wicket/behavior/Behavior.java    | 21 +++++++++++++-------
 .../java/org/apache/wicket/lambda/Lambdas.java  | 10 ++++++----
 2 files changed, 20 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/c3b845c7/wicket-core/src/main/java/org/apache/wicket/behavior/Behavior.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/behavior/Behavior.java b/wicket-core/src/main/java/org/apache/wicket/behavior/Behavior.java
index 9813aa1..55517d2 100644
--- a/wicket-core/src/main/java/org/apache/wicket/behavior/Behavior.java
+++ b/wicket-core/src/main/java/org/apache/wicket/behavior/Behavior.java
@@ -300,15 +300,20 @@ public abstract class Behavior
 	 *
 	 * <p>
 	 *     Usage:<br/>
-	 *     <code>component.add(onAttribute("class", value -> condition ? "positive" : "negative"));</code>
+	 *     <code>component.add(onAttribute("class",
+	 *              currentValue -> condition(currentValue) ? "positive" : "negative"));</code>
 	 * </p>
 	 *
-	 * @param onTagConsumer
-	 *              the {@link WicketConsumer} that accepts the {@link ComponentTag}
+	 * @param name
+	 *              the name of the attribute to manipulate
+	 * @param onAttribute
+	 *              the {@link WicketFunction} that accepts the old value of the attribute
+	 *              and returns a new value
 	 * @return The created behavior
 	 */
-	public static Behavior onAttribute(String name, WicketFunction<String, String> onAttribute)
+	public static Behavior onAttribute(String name, WicketFunction<String, CharSequence> onAttribute)
 	{
+		Args.notEmpty(name, "name");
 		Args.notNull(onAttribute, "onAttribute");
 
 		return new Behavior()
@@ -316,11 +321,13 @@ public abstract class Behavior
 			@Override
 			public void onComponentTag(Component component, ComponentTag tag)
 			{
-				if (tag.getType() != TagType.CLOSE) {
-					tag.put(name, onAttribute.apply(tag.getAttribute(name)));
+				if (tag.getType() != TagType.CLOSE)
+				{
+					String oldValue = tag.getAttribute(name);
+					tag.put(name, onAttribute.apply(oldValue));
 				}
 			}
 		};
 	}
 
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/c3b845c7/wicket-core/src/main/java/org/apache/wicket/lambda/Lambdas.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/lambda/Lambdas.java b/wicket-core/src/main/java/org/apache/wicket/lambda/Lambdas.java
index 9fa1b9e..49215ac 100644
--- a/wicket-core/src/main/java/org/apache/wicket/lambda/Lambdas.java
+++ b/wicket-core/src/main/java/org/apache/wicket/lambda/Lambdas.java
@@ -288,22 +288,24 @@ public class Lambdas
 
 	/**
 	 * Creates a {@link Behavior} that uses the given {@link WicketFunction function}
-	 * to do something with a component's attribute.
+	 * to do something with a component's attributeName.
 	 *
 	 * <p>
 	 *     Usage:<br/>
 	 *     <code>component.add(onAttribute("class", value -> condition ? "positive" : "negative"));</code>
 	 * </p>
 	 *
+	 * @param attributeName
+	 *              the name of the attribute to manipulate
 	 * @param onAttribute
 	 *              the {@link WicketFunction} that is applied to the attribute value
 	 * @return The created behavior
 	 * 
-	 * @see Behavior#onAttribute(WicketConsumer)
+	 * @see Behavior#onAttribute(String, WicketFunction)
 	 */
-	public static Behavior onAttribute(String attribute, WicketFunction<String, String> onAttribute)
+	public static Behavior onAttribute(String attributeName, WicketFunction<String, CharSequence> onAttribute)
 	{
-		return Behavior.onAttribute(attribute, onAttribute);
+		return Behavior.onAttribute(attributeName, onAttribute);
 	}
 	
 	/**