On wicket's home page http://wicket.apache.org to the left there is a Learn
-> Books section.
Under the Books page the first book is "Wicket free guide".
Download it and read chapter 9 and 10 if not the entire book.

You might be interested in section 9.2 "Models and JavaBeans" and 9.3.1
"Form and models" in particular.

In short... an empty form field has a null model object (or empty string)
and to pre-populate have your POJO that you use as a model object have its
instance variables populated with the values you want (from a db or etc).

~ Thank you,
  Paul Bors

-----Original Message-----
From: Daniel Watrous [mailto:[email protected]] 
Sent: Monday, July 15, 2013 5:41 PM
To: [email protected]
Subject: Form questions

Hello,

I'm interested in creating a single Form that will accommodate the following
use cases
1) display blank for creating new records
2) pre-populate for editing existing records
3) map submitted values on to an existing domain object
4) accommodate two actions, Save Draft -or- Publish

I'm following Wicket in Action and within my Form constructor I create my
model, like this

        CnavUrl cnavUrl = new BasicCnavUrl();
        IModel model = new Model((Serializable) cnavUrl);
        setModel(model);

I then use PropertyModel

        add(new TextField("url", new PropertyModel(cnavUrl, "url")));

For the two actions, I'm creating the Button objects like this

        add(new Button("publish", model) {
            @Override
            public void onSubmit() {
                CnavUrl cnavUrl = (CnavUrl) getModelObject();
                System.out.println("publish");
            }
        });

Some problems I can't figure out. The code to create the button complains
that it requires a CnavUrl but gets back a String.

It seems that a new BasicCnavUrl is created once with the Form. What happens
on subsequent calls? Can I always expect my model to have the data from the
current form submission?

Is there a best way to incorporate the idea of an edit, where the model is
pre-populated from a data source and pre-fills the Form fields?

Thanks,
Daniel


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to