Short form: how do I pre-fill a form field with the dynamic value of the
next free database key

Long form:

I'd like to pre-fill a form field with the value of the next free database
key. I can do this by associating the form input field with a static model
of a string value and replacing the field in the form each time the next key
value changes. Works, but hardly elegant.

So I've associated the input field with a (dynamic) property model. Because
the next key value isn't a database field I've created a new class (called
State) with a field for the next free database key. The property model I've
associated with the form field points to that attribute of State. As each
new database row is created I manually update the value of the next free key
in State. This value then finds its way into the form when it is next
displayed. So far so good. Each time the form is displayed I can see the
correct next free key value pre-filled into the form as expected.

But when the form is submitted and I do a getModelObject() on the form the
gotten object has null in the field that should contain the next free
database key. All the other fields are correctly received from the form.
(This is true more generally - in more complex forms all the form fields
that are not associated with State are correctly received from the form. All
those that are associated with State are null.)

What is weird is that if I do:

Account account = getModelObject(); // returns null in field accountNumber
which is associated with State
account.setAccountnumber(Integer.parseInt(accountNumber.getInput())); //
Gets and sets the pre-filled value

then I get the desired result i.e. field accountNumber of account is set to
the pre-filled value.

So there is no doubt that form field has the desired value - I can see it,
and getInput() gets it. But getModelObject() (which I would be expecting to
call getInput() under the covers) doesn't get the pre-filled value.

I suspect this is a question of understanding about models in general. (I've
looked at whether I should add my PropertyModel in some way to the
LoadableDetachableModel that is associated with the form but the water got
rather deep rather quickly.)

Any enlightenment appreciated.

View this message in context: 
Sent from the Users forum mailing list archive at Nabble.com.

To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to