You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by sv...@apache.org on 2016/03/15 11:37:21 UTC

[1/2] wicket git commit: WICKET-5991 allow LambdaModel to be used read-only with functionr too

Repository: wicket
Updated Branches:
  refs/heads/master 822dfd05f -> b3155edbc


WICKET-5991 allow LambdaModel to be used read-only with functionr too


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

Branch: refs/heads/master
Commit: 0ac5c90f274e9496ecac8dd5705d64987000282b
Parents: 822dfd0
Author: Sven Meier <sv...@apache.org>
Authored: Tue Mar 15 11:32:48 2016 +0100
Committer: Sven Meier <sv...@apache.org>
Committed: Tue Mar 15 11:32:48 2016 +0100

----------------------------------------------------------------------
 .../org/apache/wicket/model/LambdaModel.java    | 40 ++++++++++++++++++++
 .../apache/wicket/model/LambdaModelTest.java    | 14 +++++--
 2 files changed, 51 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/0ac5c90f/wicket-core/src/main/java/org/apache/wicket/model/LambdaModel.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/model/LambdaModel.java b/wicket-core/src/main/java/org/apache/wicket/model/LambdaModel.java
index 2dfa17c..643d4a9 100644
--- a/wicket-core/src/main/java/org/apache/wicket/model/LambdaModel.java
+++ b/wicket-core/src/main/java/org/apache/wicket/model/LambdaModel.java
@@ -116,6 +116,46 @@ public class LambdaModel<T> implements IModel<T>
 	 * Create a {@link LambdaModel} for a given target. Usage:
 	 * <pre>
 	 * {@code
+	 * 	LambdaModel.of(personModel, Person::getName)
+	 * }
+	 * </pre>
+	 * The target model will be detached automatically.
+	 *
+	 * @param targe target for getter and setter
+	 * @param getter used to get a value
+	 * @return model
+	 *
+	 * @param <X> target model object type
+	 * @param <T> model object type
+	 */
+	public static <X, T> IModel<T> of(IModel<X> target, WicketFunction<X, T> getter)
+	{
+		return new LambdaModel<T>(
+			() ->
+			{
+				X x = target.getObject();
+				if (x == null) {
+					return null;
+				}
+				return getter.apply(x);
+			},
+
+			(t) ->
+			{
+				throw new UnsupportedOperationException("setObject(Object) not supported");
+			}
+		) {
+			@Override
+			public void detach() {
+				target.detach();
+			}
+		};
+	}
+
+	/**
+	 * Create a {@link LambdaModel} for a given target. Usage:
+	 * <pre>
+	 * {@code
 	 * 	LambdaModel.of(personModel, Person::getName, Person::setName)
 	 * }
 	 * </pre>

http://git-wip-us.apache.org/repos/asf/wicket/blob/0ac5c90f/wicket-core/src/test/java/org/apache/wicket/model/LambdaModelTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/model/LambdaModelTest.java b/wicket-core/src/test/java/org/apache/wicket/model/LambdaModelTest.java
index e1f5713..b5e0eaa 100644
--- a/wicket-core/src/test/java/org/apache/wicket/model/LambdaModelTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/model/LambdaModelTest.java
@@ -19,13 +19,12 @@ package org.apache.wicket.model;
 import static org.hamcrest.Matchers.instanceOf;
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
 
 import org.apache.wicket.core.util.lang.WicketObjects;
 import org.apache.wicket.lambda.WicketConsumer;
 import org.apache.wicket.lambda.WicketSupplier;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.LambdaModel;
 import org.apache.wicket.model.lambda.Person;
 import org.junit.Test;
 
@@ -61,6 +60,15 @@ public class LambdaModelTest
 		check(personNameModel);
 	}
 
+	@Test(expected=UnsupportedOperationException.class)
+	public void targetReadOnly()
+	{
+		IModel<Person> target = Model.of(new Person());
+
+		IModel<String> personNameModel = LambdaModel.of(target, Person::getName);
+		check(personNameModel);
+	}
+
 	@Test
 	public void equality()
 	{


[2/2] wicket git commit: restored CDI entries

Posted by sv...@apache.org.
restored CDI entries


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

Branch: refs/heads/master
Commit: b3155edbc00291122c4faff42f199a872d8cfdba
Parents: 0ac5c90
Author: Sven Meier <sv...@apache.org>
Authored: Tue Mar 15 11:37:07 2016 +0100
Committer: Sven Meier <sv...@apache.org>
Committed: Tue Mar 15 11:37:07 2016 +0100

----------------------------------------------------------------------
 wicket-examples/src/main/webapp/WEB-INF/web.xml | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/b3155edb/wicket-examples/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/webapp/WEB-INF/web.xml b/wicket-examples/src/main/webapp/WEB-INF/web.xml
index e73ec90..fb326f9 100644
--- a/wicket-examples/src/main/webapp/WEB-INF/web.xml
+++ b/wicket-examples/src/main/webapp/WEB-INF/web.xml
@@ -784,6 +784,26 @@
 	</filter-mapping>
 
 
+	<!-- CDI EXAMPLE APPLICATION -->
+	<filter>
+		<filter-name>CdiApplication</filter-name>
+		<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
+		<init-param>
+		  <param-name>applicationClassName</param-name>
+		  <param-value>org.apache.wicket.examples.cdi.CdiApplication</param-value>
+		</init-param>
+	</filter>
+	<filter-mapping>
+		<filter-name>CdiApplication</filter-name>
+		<url-pattern>/cdi/*</url-pattern>
+	</filter-mapping>
+
+	<listener>
+		<!-- initialize Weld in servlet environment -->
+		<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
+	</listener>
+    <!-- END CDI EXAMPLE APPLICATION -->
+
     <!-- Bean Validation EXAMPLE APPLICATION -->
     <filter>
         <filter-name>BeanValidation</filter-name>