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 2017/04/04 15:38:09 UTC

[2/8] wicket git commit: WICKET-6348 guide update for FormComponentUpdatingBehavior

WICKET-6348 guide update for FormComponentUpdatingBehavior


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

Branch: refs/heads/master
Commit: ad429c19d6dd6486bd01b20ddf1d9bd16bca146e
Parents: c1d389d
Author: Sven Meier <sv...@apache.org>
Authored: Thu Mar 30 17:05:14 2017 +0200
Committer: Sven Meier <sv...@apache.org>
Committed: Tue Apr 4 17:30:04 2017 +0200

----------------------------------------------------------------------
 .../src/main/asciidoc/advanced/advanced_2.adoc  |  4 +-
 .../src/main/asciidoc/forms2/forms2_11.adoc     |  2 +-
 .../asciidoc/modelsforms/modelsforms_6.adoc     | 50 ++++++++------------
 3 files changed, 23 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/ad429c19/wicket-user-guide/src/main/asciidoc/advanced/advanced_2.adoc
----------------------------------------------------------------------
diff --git a/wicket-user-guide/src/main/asciidoc/advanced/advanced_2.adoc b/wicket-user-guide/src/main/asciidoc/advanced/advanced_2.adoc
index c03c060..0ec6a2f 100644
--- a/wicket-user-guide/src/main/asciidoc/advanced/advanced_2.adoc
+++ b/wicket-user-guide/src/main/asciidoc/advanced/advanced_2.adoc
@@ -53,9 +53,9 @@ public abstract class Link<T> extends AbstractLink implements IRequestListener .
 }
 ----
 
-Callback URLs can be generated with _Component_'s method _urlFor(PageParameters)_ or with method _urlFor (Behavior, RequestListenerInterface, PageParameters)_ if we are using a callback interface with a behavior (see the following example).
+Callback URLs can be generated with _Component_'s method _urlForListener(PageParameters)_ or with method _urlForListener(Behavior, PageParameters)_ if we are using a request listener on a component or behavior respectively (see the following example).
 
-Project _CallbackURLExample_ contains a behavior (class _OnChangeSingleChoiceBehavior_) that implements _org.apache.wicket.IRequestListener_ to update the model of an _AbstractSingleSelectChoice_ component when user changes the selected option (it provides the same functionality of method _wantOnSelectionChangedNotifications_). 
+Project _CallbackURLExample_ contains a behavior (class _OnChangeSingleChoiceBehavior_) that implements _org.apache.wicket.IRequestListener_ to update the model of an _AbstractSingleSelectChoice_ component when user changes the selected option (it provides the same functionality as _FormComponentUpdatingBehavior_). 
 The following is the implementation of _onRequest()_ provided by _OnSelectionChangedNotifications_:
 
 [source,java]

http://git-wip-us.apache.org/repos/asf/wicket/blob/ad429c19/wicket-user-guide/src/main/asciidoc/forms2/forms2_11.adoc
----------------------------------------------------------------------
diff --git a/wicket-user-guide/src/main/asciidoc/forms2/forms2_11.adoc b/wicket-user-guide/src/main/asciidoc/forms2/forms2_11.adoc
index 9f8a7ed..371350d 100644
--- a/wicket-user-guide/src/main/asciidoc/forms2/forms2_11.adoc
+++ b/wicket-user-guide/src/main/asciidoc/forms2/forms2_11.adoc
@@ -195,5 +195,5 @@ form.add(new RadioChoice("radioGroup", Model.of(""), fruits));
 
 image::../img/grouped-radiobutton.png[]
 
-Just like CheckBoxMultipleChoice, this component provides the setPrefix and setSuffix methods to configure the prefix and suffix for our options and it supports IChoiceRender as well. In addition, RadioChoice provides the wantOnSelectionChangedNotifications() method to notify the web server when the selected option changes (this is the same method seen for DropDownChoice in paragraph 9.4).
+Just like CheckBoxMultipleChoice, this component provides the setPrefix and setSuffix methods to configure the prefix and suffix for our options and it supports IChoiceRender as well.
 

http://git-wip-us.apache.org/repos/asf/wicket/blob/ad429c19/wicket-user-guide/src/main/asciidoc/modelsforms/modelsforms_6.adoc
----------------------------------------------------------------------
diff --git a/wicket-user-guide/src/main/asciidoc/modelsforms/modelsforms_6.adoc b/wicket-user-guide/src/main/asciidoc/modelsforms/modelsforms_6.adoc
index f7d4b1c..3a4f39e 100644
--- a/wicket-user-guide/src/main/asciidoc/modelsforms/modelsforms_6.adoc
+++ b/wicket-user-guide/src/main/asciidoc/modelsforms/modelsforms_6.adoc
@@ -7,7 +7,7 @@ The example page will look like this:
 
 image::../img/model-chaining.png[]
 
-What we want to do in this example is to chain the model of the DropDownChoice (which contains the selected Person) with the model of the Form. In this way the Form will work with the selected Person as backing object. The DropDownChoice component can be configured to automatically update its model each time we change the selected item on the client side. All we have to do is to override method wantOnSelectionChangedNotifications to make it return true. In practice, when this method returns true, DropDownChoice will submit its value every time JavaScript event onChange occurs, and its model will be consequently updated. To leverage this functionality, DropDownChoice doesn't need to be inside a form.
+What we want to do in this example is to chain the model of the DropDownChoice (which contains the selected Person) with the model of the Form. In this way the Form will work with the selected Person as backing object. The DropDownChoice component can be configured to automatically update its model each time we change the selected item on the client side. All we have to do is to add a FormComponentUpdatingBehavior to it: The behavior will submit the components value every time JavaScript event "change" occurs, and its model will be consequently updated. To leverage this functionality, the form component doesn't need to be inside a form.
 
 The following is the resulting markup of the example page:
 
@@ -55,14 +55,8 @@ The initialization code for DropDownChoice is the following:
 ----
 Model<Person> listModel = new Model<Person>();
 ChoiceRenderer<Person> personRender = new ChoiceRenderer<Person>("fullName");
-personsList = new DropDownChoice<Person>("persons", listModel, loadPersons(), personRender){
-		
-		@Override
-		protected boolean wantOnSelectionChangedNotifications() {
-			return true;
-		}
-		
-};
+personsList = new DropDownChoice<Person>("persons", listModel, loadPersons(), personRender);
+personsList.add(new FormComponentUpdatingBehavior());
 ----
 
 As choice render we have used the basic implementation provided with the org.apache.wicket .markup.html.form.ChoiceRenderer class that we have seen in the previous paragraph. loadPersons() is just an utility method which generates a list of Person instances. The model for DropDownChoice is a simple instance of the Model class.
@@ -79,27 +73,23 @@ public class PersonListDetails extends WebPage {
     Model<Person> listModel = new Model<Person>();
     ChoiceRenderer<Person> personRender = new ChoiceRenderer<Person>("fullName");
     
-    personsList = new DropDownChoice<Person>("persons", listModel, loadPersons(),
-                                                         personRender){
-      @Override
-      protected boolean wantOnSelectionChangedNotifications() {
-        return true;
-      }
-	    };    
-
-	    add(personsList);
-
-	    form = new Form("form", new CompoundPropertyModel<Person>(listModel));    
-	    form.add(new TextField("name"));
-	    form.add(new TextField("surname"));
-	    form.add(new TextField("address"));
-	    form.add(new TextField("email"));
-
-	    add(form);
-	  }
-	       //loadPersons()
-	       //...
-	}
+    personsList = new DropDownChoice<Person>("persons", listModel, loadPersons(), personRender);
+    personsList.add(new FormComponentUpdatingBehavior());
+
+    add(personsList);
+
+    form = new Form("form", new CompoundPropertyModel<Person>(listModel));    
+    form.add(new TextField("name"));
+    form.add(new TextField("surname"));
+    form.add(new TextField("address"));
+    form.add(new TextField("email"));
+
+    add(form);
+  }
+
+       //loadPersons()
+       //...
+}
 ----
 
 The two models work together as a pipeline where the output of method getObject of Model is the model object of CompoundPropertyModel. As we have seen, model chaining allows us to combine the actions of two or more models without creating new custom implementations.