Martin,
The problem is here:
add(new TestForm("testForm", new Model(person)));

You are creating a Model, when in fact you should be creating a
CompoundPropertyModel.
Components that do not have models ( ie your RequiredTextField ) only
"inherit" models that are of type CompoundPropertyModel or derivatives there
of.

To fix your example try
add(new TestForm("testForm", new CompoundPropertyModel(person)));

See the model wiki page for more explanations on models.
http://wicket.sourceforge.net/wiki/index.php/Models

Igor


 

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Martin Bednár
Sent: Tuesday, July 05, 2005 8:37 AM
To: wicket-user@lists.sourceforge.net
Subject: [Wicket-user] Newbie problem with Model-s

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_idt77&alloc_id492&op=click
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to