That is because you did override a method, Form.onFormSubmitted, that was not meant for that. We try to shield you from this kind of errors as much as possible with Wicket, but sometimes that is not possible. In this case we couldn't make onFormSubmitted not final as we needed to override this in UploadForm, and maybe more. That's why we put fat warnings with method comments if they are not meant for direct use and/ or overriding. This one:

   /**
* THIS METHOD IS NOT PART OF THE WICKET API. DO NOT ATTEMPT TO OVERRIDE OR
    * CALL IT.
    *
* Handles form submissions. By default, this method simply calls validate() * to validate the form and update the model if there is only one button. If
    * there is more than one button, it calls the onClick() method for the
    * button which submitted the form.
    *
    * @see Form#validate()
    */
   public void onFormSubmitted()
   {

So... to fix your problem, use onSubmit instead:

   class TestForm extends Form {
       public TestForm(String id, IModel model) {
           super(id, model, null);
           add(new RequiredTextField("name", new PropertyModel(
                   model, "name")));
       }

       public void onSubmit() {
           System.out.println(((Person) getModelObject()).getName());
       }
   }

Furthermore, I didn't see a submit button, so you'll need to put that in as well:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
<title>My Wicket Example</title>
</head>
<body>
<form wicket:id="testForm">
Name: <input type="text" wicket:id="name"/>
<input type="submit" value="save" />
</form>
</body>
</html>

Good luck,

Eelco

Martin Bednář wrote:

Hi,
I have problems with updating models with data from page, I can't uderstand why it dosn't work :(
Can anybody tell me what I'am doing wrong ?
There is my very simple sample.

package wicket.examples.my;
import java.io.Serializable;
import wicket.markup.html.WebPage;
import wicket.markup.html.form.Form;
import wicket.markup.html.form.RequiredTextField;
import wicket.model.IModel;
import wicket.model.Model;
import wicket.model.PropertyModel;

public class TestFieldPage extends WebPage {
   class Person implements Serializable {
       private String name = "TEST";

       public void setName(String name) {
           this.name = name;
       }

       public String getName() {
           return name;
       }
   }

   public TestFieldPage() {
       Person person = new Person();
       add(new TestForm("testForm", new Model(person)));
   }

   class TestForm extends Form {
       public TestForm(String id, IModel model) {
           super(id, model, null);
           add(new RequiredTextField("name", new PropertyModel(
                   model, "name")));
       }

       public void onFormSubmitted() {
           System.out.println(((Person) getModelObject()).getName());
       }
   }
}

with this markup:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
<title>My Wicket Example</title>
</head>
<body>
<form wicket:id="testForm">
Name: <input type="text" wicket:id="name"/>
</form>
</body>
</html>



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user




-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to