Author: ivaynberg
Date: Mon Dec 11 09:53:00 2006
New Revision: 485775
URL: http://svn.apache.org/viewvc?view=rev&rev=485775
Log:
WICKET-115: Example using RefreshingView in a form: contacts editor
Added:
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/FormPage$ActionPanel.html
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/FormPage.html
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/FormPage.java
Modified:
incubator/wicket/branches/wicket-1.x/wicket-examples/.classpath
incubator/wicket/branches/wicket-1.x/wicket-examples/.settings/org.eclipse.core.resources.prefs
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/BasePage$ActionPanel.html
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/BasePage.html
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/BasePage.java
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/Index.html
Modified: incubator/wicket/branches/wicket-1.x/wicket-examples/.classpath
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket-examples/.classpath?view=diff&rev=485775&r1=485774&r2=485775
==============================================================================
--- incubator/wicket/branches/wicket-1.x/wicket-examples/.classpath (original)
+++ incubator/wicket/branches/wicket-1.x/wicket-examples/.classpath Mon Dec 11
09:53:00 2006
@@ -3,6 +3,8 @@
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" output="target/test-classes"
path="src/test/java"/>
<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
+ <classpathentry combineaccessrules="false" kind="src"
path="/wicket-1.x"/>
+ <classpathentry combineaccessrules="false" kind="src"
path="/wicket-extensions-1.x"/>
<classpathentry kind="var"
path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"
sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/>
<classpathentry kind="var"
path="M2_REPO/mx4j/mx4j-tools/3.0.1/mx4j-tools-3.0.1.jar"
sourcepath="M2_REPO/mx4j/mx4j-tools/3.0.1/mx4j-tools-3.0.1-sources.jar"/>
<classpathentry kind="var"
path="M2_REPO/org/mortbay/jetty/jetty/6.0.1/jetty-6.0.1.jar"
sourcepath="M2_REPO/org/mortbay/jetty/jetty/6.0.1/jetty-6.0.1-sources.jar"/>
@@ -24,7 +26,6 @@
<classpathentry kind="var"
path="M2_REPO/javax/servlet/servlet-api/2.3/servlet-api-2.3.jar"
sourcepath="M2_REPO/javax/servlet/servlet-api/2.3/servlet-api-2.3-sources.jar"/>
<classpathentry kind="var"
path="M2_REPO/org/mortbay/jetty/jetty-util/6.0.1/jetty-util-6.0.1.jar"
sourcepath="M2_REPO/org/mortbay/jetty/jetty-util/6.0.1/jetty-util-6.0.1-sources.jar"/>
<classpathentry kind="var"
path="M2_REPO/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar"
sourcepath="M2_REPO/dom4j/dom4j/1.6.1/dom4j-1.6.1-sources.jar"/>
- <classpathentry kind="var"
path="M2_REPO/org/mortbay/jetty/jetty-management/6.0.1/jetty-management-6.0.1.jar"
sourcepath="M2_REPO/org/mortbay/jetty/jetty-management/6.0.1/jetty-management-6.0.1-sources.jar"/>
<classpathentry kind="var"
path="M2_REPO/commons-lang/commons-lang/2.0/commons-lang-2.0.jar"
sourcepath="M2_REPO/commons-lang/commons-lang/2.0/commons-lang-2.0-sources.jar"/>
<classpathentry kind="var"
path="M2_REPO/jtidy/jtidy/4aug2000r7-dev/jtidy-4aug2000r7-dev.jar"
sourcepath="M2_REPO/jtidy/jtidy/4aug2000r7-dev/jtidy-4aug2000r7-dev-sources.jar"/>
<classpathentry kind="var"
path="M2_REPO/tomcat/jasper-compiler/4.1.30/jasper-compiler-4.1.30.jar"
sourcepath="M2_REPO/tomcat/jasper-compiler/4.1.30/jasper-compiler-4.1.30-sources.jar"/>
@@ -33,7 +34,5 @@
<classpathentry kind="var"
path="M2_REPO/httpunit/httpunit/1.6/httpunit-1.6.jar"
sourcepath="M2_REPO/httpunit/httpunit/1.6/httpunit-1.6-sources.jar"/>
<classpathentry kind="var"
path="M2_REPO/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar"
sourcepath="M2_REPO/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2-sources.jar"/>
<classpathentry kind="var"
path="M2_REPO/javax/portlet/portlet-api/1.0/portlet-api-1.0.jar"/>
- <classpathentry combineaccessrules="false" kind="src" path="/wicket"/>
- <classpathentry combineaccessrules="false" kind="src"
path="/wicket-extensions"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Modified:
incubator/wicket/branches/wicket-1.x/wicket-examples/.settings/org.eclipse.core.resources.prefs
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket-examples/.settings/org.eclipse.core.resources.prefs?view=diff&rev=485775&r1=485774&r2=485775
==============================================================================
---
incubator/wicket/branches/wicket-1.x/wicket-examples/.settings/org.eclipse.core.resources.prefs
(original)
+++
incubator/wicket/branches/wicket-1.x/wicket-examples/.settings/org.eclipse.core.resources.prefs
Mon Dec 11 09:53:00 2006
@@ -1,12 +1,12 @@
-#Sat Dec 02 10:20:15 PST 2006
-eclipse.preferences.version=1
-encoding//src/java/wicket/examples/forminput/FormInput_da_DK.html=UTF-8
-encoding//src/java/wicket/examples/forminput/FormInput_de.html=UTF-8
-encoding//src/java/wicket/examples/forminput/FormInput_fa_IR.html=UTF-8
-encoding//src/java/wicket/examples/forminput/FormInput_ja.html=UTF-8
-encoding//src/java/wicket/examples/forminput/FormInput_pt_BR.html=ISO-8859-1
-encoding//src/java/wicket/examples/forminput/FormInput_zh_CN.html=UTF-8
-encoding//src/java/wicket/examples/pub/Home_da_DK.html=UTF-8
-encoding//src/main/java/wicket/examples/forminput/FormInput_da_DK.properties=UTF-8
-encoding//src/main/java/wicket/examples/forminput/FormInput_de.properties=UTF-8
-encoding//src/main/java/wicket/examples/forminput/FormInput_pt_BR.properties=ISO-8859-1
+#Fri Dec 08 17:47:34 PST 2006
+eclipse.preferences.version=1
+encoding//src/java/wicket/examples/forminput/FormInput_da_DK.html=UTF-8
+encoding//src/java/wicket/examples/forminput/FormInput_de.html=UTF-8
+encoding//src/java/wicket/examples/forminput/FormInput_fa_IR.html=UTF-8
+encoding//src/java/wicket/examples/forminput/FormInput_ja.html=UTF-8
+encoding//src/java/wicket/examples/forminput/FormInput_pt_BR.html=ISO-8859-1
+encoding//src/java/wicket/examples/forminput/FormInput_zh_CN.html=UTF-8
+encoding//src/java/wicket/examples/pub/Home_da_DK.html=UTF-8
+encoding//src/main/java/wicket/examples/forminput/FormInput_da_DK.properties=UTF-8
+encoding//src/main/java/wicket/examples/forminput/FormInput_de.properties=UTF-8
+encoding//src/main/java/wicket/examples/forminput/FormInput_pt_BR.properties=ISO-8859-1
Modified:
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/BasePage$ActionPanel.html
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/BasePage%24ActionPanel.html?view=diff&rev=485775&r1=485774&r2=485775
==============================================================================
---
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/BasePage$ActionPanel.html
(original)
+++
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/BasePage$ActionPanel.html
Mon Dec 11 09:53:00 2006
@@ -1,3 +1,3 @@
<wicket:panel>
<a href="#" wicket:id="select">select</a>
-</wicket:panel>
\ No newline at end of file
+</wicket:panel>
Modified:
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/BasePage.html
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/BasePage.html?view=diff&rev=485775&r1=485774&r2=485775
==============================================================================
---
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/BasePage.html
(original)
+++
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/BasePage.html
Mon Dec 11 09:53:00 2006
@@ -2,5 +2,6 @@
<span style="display: block; border: 1px solid black;">
Selected Contact: <span wicket:id="selectedLabel">[selected contact]</span>
</span><br/>
+<span wicket:id="feedback">Feedback messages go here</span>
<wicket:child/>
-</wicket:extend>
\ No newline at end of file
+</wicket:extend>
Modified:
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/BasePage.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/BasePage.java?view=diff&rev=485775&r1=485774&r2=485775
==============================================================================
---
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/BasePage.java
(original)
+++
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/BasePage.java
Mon Dec 11 09:53:00 2006
@@ -19,6 +19,7 @@
import wicket.markup.html.basic.Label;
import wicket.markup.html.link.Link;
+import wicket.markup.html.panel.FeedbackPanel;
import wicket.markup.html.panel.Panel;
import wicket.model.IModel;
import wicket.model.PropertyModel;
@@ -38,6 +39,7 @@
public BasePage()
{
add(new Label("selectedLabel", new PropertyModel(this,
"selectedContactLabel")));
+ add(new FeedbackPanel("feedback"));
}
/**
@@ -77,5 +79,15 @@
}
});
}
+ }
+
+ public Contact getSelected()
+ {
+ return selected;
+ }
+
+ public void setSelected(Contact selected)
+ {
+ this.selected = selected;
}
}
Added:
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/FormPage$ActionPanel.html
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/FormPage%24ActionPanel.html?view=auto&rev=485775
==============================================================================
---
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/FormPage$ActionPanel.html
(added)
+++
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/FormPage$ActionPanel.html
Mon Dec 11 09:53:00 2006
@@ -0,0 +1,4 @@
+<wicket:panel>
+<a href="#" wicket:id="select">select</a>
+<a href="#" wicket:id="remove">remove</a>
+</wicket:panel>
Added:
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/FormPage.html
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/FormPage.html?view=auto&rev=485775
==============================================================================
---
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/FormPage.html
(added)
+++
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/FormPage.html
Mon Dec 11 09:53:00 2006
@@ -0,0 +1,28 @@
+<wicket:extend>
+
+This page allows to edit the entries in the address book shown in
« RefreshingView Example ». It illustrates using a
+RefreshingView in a form, with a <tt>remove</tt> link along with each item.
+<br/><br/>
+
+<form wicket:id="form">
+<table cellspacing="0" class="dataview">
+ <tr>
+ <th>Actions</th>
+ <th>ID</th>
+ <th>First Name</th>
+ <th>Last Name</th>
+ <th>Home Phone</th>
+ <th>Cell Phone</th>
+ </tr>
+ <tr wicket:id="simple">
+ <td><span wicket:id="actions">[actions]</span></td>
+ <td><input type="text" wicket:id="id">[contactid]</input> </td>
+ <td><input type="text"
wicket:id="firstName">[firstname]</input></td>
+ <td><input type="text"
wicket:id="lastName">[lastname]</input></td>
+ <td><input type="text"
wicket:id="homePhone">[homephone]</input></td>
+ <td><input type="text"
wicket:id="cellPhone">[cellphone]</input></td>
+ </tr>
+</table>
+</form>
+
+</wicket:extend>
Added:
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/FormPage.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/FormPage.java?view=auto&rev=485775
==============================================================================
---
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/FormPage.java
(added)
+++
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/FormPage.java
Mon Dec 11 09:53:00 2006
@@ -0,0 +1,141 @@
+/*
+ * $Id$ $Revision: 460265 $ $Date: 2006-04-16 15:36:52 +0200 (Dim, 16 avr
2006) $
+ *
+ * ====================================================================
Licensed
+ * under the Apache License, Version 2.0 (the "License"); you may not use this
+ * file except in compliance with the License. You may obtain a copy of the
+ * License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package wicket.examples.repeater;
+
+import java.util.Iterator;
+
+import wicket.extensions.markup.html.repeater.refreshing.Item;
+import wicket.extensions.markup.html.repeater.refreshing.OddEvenItem;
+import wicket.extensions.markup.html.repeater.refreshing.RefreshingView;
+import
wicket.extensions.markup.html.repeater.refreshing.ReuseIfModelsEqualStrategy;
+import wicket.extensions.markup.html.repeater.util.ModelIteratorAdapter;
+import wicket.markup.html.form.Form;
+import wicket.markup.html.form.SubmitLink;
+import wicket.markup.html.form.TextField;
+import wicket.markup.html.link.Link;
+import wicket.markup.html.panel.Panel;
+import wicket.model.IModel;
+import wicket.model.PropertyModel;
+
+/**
+ * Page that demonstrates using RefreshingView in a form. The component reuses
+ * its items, to allow adding or removing rows without necessarily validating
+ * the form.
+ */
+public class FormPage extends BasePage
+{
+ final Form form;
+
+ /**
+ * constructor
+ */
+ public FormPage()
+ {
+ form = new Form("form");
+ add(form);
+
+ // create a repeater that will display the list of contacts.
+ RefreshingView refreshingView = new RefreshingView("simple")
+ {
+ protected Iterator getItemModels()
+ {
+ // for simplicity we only show the first 10
contacts
+ Iterator contacts =
DatabaseLocator.getDatabase().find(0, 10, "firstName", true)
+ .iterator();
+
+ // the iterator returns contact objects, but we
need it to
+ // return models, we use this handy adapter
class to perform
+ // on-the-fly conversion.
+ return new ModelIteratorAdapter(contacts)
+ {
+
+ protected IModel model(Object object)
+ {
+ return new
DetachableContactModel((Contact)object);
+ }
+
+ };
+
+ }
+
+ protected void populateItem(final Item item)
+ {
+ // populate the row of the repeater
+ IModel contact = item.getModel();
+ item.add(new ActionPanel("actions", contact));
+ // FIXME use CompoundPropertyModel!
+ item.add(new TextField("id", new
PropertyModel(contact, "id")));
+ item.add(new TextField("firstName", new
PropertyModel(contact, "firstName")));
+ item.add(new TextField("lastName", new
PropertyModel(contact, "lastName")));
+ item.add(new TextField("homePhone", new
PropertyModel(contact, "homePhone")));
+ item.add(new TextField("cellPhone", new
PropertyModel(contact, "cellPhone")));
+ }
+
+ protected Item newItem(String id, int index, IModel
model)
+ {
+ // this item sets markup class attribute to
either 'odd' or
+ // 'even' for decoration
+ return new OddEvenItem(id, index, model);
+ }
+ };
+
+ // because we are in a form we need to preserve state of the
component
+ // hierarchy (because it might contain things like form errors
that
+ // would be lost if the hierarchy for each item was recreated
every
+ // request by default), so we use an item reuse strategy.
+
refreshingView.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance());
+
+
+ form.add(refreshingView);
+ }
+
+ /**
+ * Panel that houses row-actions
+ */
+ class ActionPanel extends Panel
+ {
+ /**
+ * @param id
+ * component id
+ * @param model
+ * model for contact
+ */
+ public ActionPanel(String id, IModel model)
+ {
+ super(id, model);
+ add(new Link("select")
+ {
+ public void onClick()
+ {
+
FormPage.this.setSelected((Contact)getParent().getModelObject());
+ }
+ });
+
+ SubmitLink removeLink;
+ add(removeLink = new SubmitLink("remove", form)
+ {
+ public void onSubmit()
+ {
+ Contact contact =
(Contact)getParent().getModelObject();
+ info("Removed contact " + contact);
+
DatabaseLocator.getDatabase().delete(contact);
+ }
+ });
+ removeLink.setDefaultFormProcessing(false);
+ }
+ }
+}
Modified:
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/Index.html
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/Index.html?view=diff&rev=485775&r1=485774&r2=485775
==============================================================================
---
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/Index.html
(original)
+++
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/repeater/Index.html
Mon Dec 11 09:53:00 2006
@@ -6,6 +6,7 @@
<wicket:link>
<a href="RepeatingPage.html">OrderedRepeatingView Example - basic example of a
repeater view</a><br/>
<a href="RefreshingPage.html">RefreshingView Example - basic view that
recreates its items every request</a><br/>
+<a href="FormPage.html">Contacts Editor - based on the previous example, but
with editable values.</a><br/>
<a href="SimplePage.html">Simple DataView Example - simple example of a
dataview</a><br/>
<a href="PagingPage.html">Paging DataView Example - builds on previous to
demonstrate paging and page navigation</a><br/>
<a href="SortingPage.html">Sorting DataView Example - builds on previous to
demonstrate sorting</a><br/>
@@ -15,4 +16,4 @@
<a href="GridViewPage.html">GridView Example - demonstrates a grid
view</a><br/>
<a href="AjaxDataTablePage.html">AjaxFallbackDataTable Example - demonstrates
an AJAX enabled datatable component</a><br/><br/>
</wicket:link>
-</wicket:extend>
\ No newline at end of file
+</wicket:extend>