G'day In part the question was based on a misunderstanding which I have now overcome. I thought that all the columns of the database table had to be present in the form as form fields. This meant that I had to pre-fill values for the key fields. This indeed has the difficulties that you raise. But it is not the case that all the columns need to be in the form. So I no longer show the key fields but provide values for their columns after I retrieve the form with GetModelObject(). That side-steps the difficulties you mention. And, yes, I now need in some cases to show the user the key value that was generated. I've done that crudely with a form that becomes visible after the database row has been successfully created. But I will replace that with a reusable model window in due course. (Unless Wicket 5 has a simpler dialog box feature that I haven't yet discovered. I don't want to do the dialog box in Javascript).
But that still leaves the question of why the pre-filled values weren't retrieved by the GetModelObject(). Their values are associated with a model other than the model that is associated with form - is that the reason ? Seems reasonable, except that if the pre-filled form fields are associated with a static model (rather than the (dynamic) PropertyModel that I currently use) then the pre-filled values are correctly retrieved by GetModelObject(). Ian Blavins On 18/07/2012, at 1:42 AM, Alec Swan [via Apache Wicket] wrote: > How do you determine which next key is available? If two users open > the form at the same time will they see the same key? If so, then you > need to handle errors from concurrent form submissions with the same > key. Which means for one of these concurrent requests you will have to > issue a different key and show it to the user after the form was > submitted. So, why not show the key after form submission all the > time? > > On Sat, Jul 14, 2012 at 1:03 AM, Ian <[hidden email]> wrote: > > > G'day > > > > 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: > > http://apache-wicket.1842946.n4.nabble.com/Next-database-key-pre-filled-in-form-and-associated-with-PropertyModel-returns-null-tp4650518.html > > Sent from the Users forum mailing list archive at Nabble.com. > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [hidden email] > > For additional commands, e-mail: [hidden email] > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > > > > If you reply to this email, your message will be added to the discussion > below: > http://apache-wicket.1842946.n4.nabble.com/Next-database-key-pre-filled-in-form-and-associated-with-PropertyModel-returns-null-tp4650518p4650573.html > To unsubscribe from Next database key pre-filled in form and associated with > PropertyModel returns null, click here. > NAML -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Next-database-key-pre-filled-in-form-and-associated-with-PropertyModel-returns-null-tp4650518p4650582.html 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