Re: Next database key pre-filled in form and associated with PropertyModel returns null
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. > > > > > >
Re: Next database key pre-filled in form and associated with PropertyModel returns null
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. But that is not the case. So any column whose value I know ahead of time I don't present on the form - I just give them values in the code after the user submits the form. I also came to the same conclusion about the database keys. So that reduces the question to form fields that I want to pre-fill with a (context-dependent) default value but whose value I allow the user to change. I can pre-fill the fields using a Property model as described in the initial post, but such values are null after the GetModelObject(). Is this a misunderstanding about models - that the GetModelObject won't get the values of form fields that are linked with a model other than the model the form is linked with. Seems reasonable, except that if the pre-filled fields are linked with a static model instead of the (dynamic) PropertyModel the form values are retrieved correctly by GetModelObject(). Ian Blavins On 18/07/2012, at 4:22 AM, Eric Jablow [via Apache Wicket] wrote: > On Sat, Jul 14, 2012 at 3: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 > > > > Is your customer demanding that the database ids end up without > any gaps? If so, try to work hard to dissuade your customer. Database > ids should have no other business meeting. They should be opaque. > One good way to distinguish between a object that has not yet been > persisted and one that has is whether its id variable is null or not. > > So, suppose you have a Form. In your onSubmit method, you > call personService.create(getModelObject()), where personService > calls DAOs, or maybe is a DAO. It modifies the Person object in place, > setting the id when it is done. It then redirects the user to the > appropriate > page. If there is a constraint violation or other database problem, > the object should be unchanged and the system should remain on > the form page. > > You can reuse the form page if you want to edit an existing person. You > just don't give the user any way to edit the id, and you call an update > method instead. > > Respectfully, > Eric Jablow > > > 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-tp4650518p4650576.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-tp4650518p4650581.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
Re: Next database key pre-filled in form and associated with PropertyModel returns null
On Sat, Jul 14, 2012 at 3:03 AM, Ian wrote: > G'day > > Short form: how do I pre-fill a form field with the dynamic value of the > next free database key > > Is your customer demanding that the database ids end up without any gaps? If so, try to work hard to dissuade your customer. Database ids should have no other business meeting. They should be opaque. One good way to distinguish between a object that has not yet been persisted and one that has is whether its id variable is null or not. So, suppose you have a Form. In your onSubmit method, you call personService.create(getModelObject()), where personService calls DAOs, or maybe is a DAO. It modifies the Person object in place, setting the id when it is done. It then redirects the user to the appropriate page. If there is a constraint violation or other database problem, the object should be unchanged and the system should remain on the form page. You can reuse the form page if you want to edit an existing person. You just don't give the user any way to edit the id, and you call an update method instead. Respectfully, Eric Jablow
Re: Next database key pre-filled in form and associated with PropertyModel returns null
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 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: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Next database key pre-filled in form and associated with PropertyModel returns null
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: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org