Hi Jong,

for this aproach to work you will need to re implement formBackingObject
method,
for ItemsForm to have items List instantiated an populated with Item objects
and in proper order
as spring will try to bind params with something equivalent to :

form.getItems().get(0).setDescription(request.getParameter("form.items[0].description"));

other wise you may get NullPointerExceptions or be binding to the wrong item
...

Regards
Ivan


Jong Hian Zin wrote:
> 
> Jonathan,
> 
> Thanks for your reply.
> 
> I have another question. If my domain object has 3 fields, eg. id,
> name, description. These are the records in database:
> 
> id  |  name  |  description
> 
> 1  |  Name 1  |  Description 1
> 2  |  Name 2  |  Description 2
> 3  |  Name 3  |  Description 3
> 
> Now, if I only need to update the 'description' field, I have this in my
> form:
> 
> <form>
>    <input type="hidden" name="form.items[0].id" value="1">
>    <input type="text" name="form.items[0].description" value="Description
> 1">
> 
>    <input type="hidden" name="form.items[1].id" value="2">
>    <input type="text" name="form.items[1].description" value="Description
> 2">
> 
>    <input type="hidden" name="form.items[2].id" value="3">
>    <input type="text" name="form.items[2].description" value="Description
> 3">
>    ...
> </form>
> 
> Note that my 'name' field is not specified in the form. If the index
> of the list is not reliable, is there any possibility that the 'id'
> and 'description' fields being updated correctly, but the 'name' field
> (which is not specified in the form) being updated incorrectly? eg.
> 
> id  |  name  |  description
> 
> 1  |  Name 2  |  Description 1
> 2  |  Name 3  |  Description 2
> 3  |  Name 1  |  Description 3
> 
> Will this happen? Will the binder or dao take care of this automatically?
> 
> 
> On 4/13/07, Jonathan Tse <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>>     I have done something like this before and i suggest that you should
>> include an id when posting to SFC. In this way, you can guarantee that
>> your dao will update the database with the correct id. Don't rely on the
>> index of the list as the command object is not stored in the session. It
>> is fetched from the db again when you post the form and so the data may
>> not be the same. Please correct me if I am wrong.
>>
>> Best regards,
>> Jonathan
>>
>> Jong Hian Zin wrote:
>> > This is rather Spring MVC specific. Let say I'm using
>> > SimpleFormController and I have a command object that looks like this:
>> >
>> > public class ItemsForm {
>> >    List<Item> items;
>> > }
>> >
>> > A domain object Item:
>> >
>> > public class Item {
>> >    private String id;
>> >    private String description;
>> >
>> >    // getters and setters...
>> > }
>> >
>> > Suppose my command name is "form", the rendered view may look like
>> > this (by formBackingObject()):
>> >
>> > <form>
>> >    <input type="text" name="form.items[0].description" value="...">
>> >    <input type="text" name="form.items[1].description" value="...">
>> >    <input type="text" name="form.items[2].description" value="...">
>> >    ...
>> > </form>
>> >
>> > So, my question is, do we need to include the id as hidden fields like
>> > form.items[0].id, etc in the form? How does Spring MVC know how to
>> > bind each item in the list of items during onSubmit? Is it by the
>> > index of the array or is it by the id?
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
> 
> 
> -- 
> Jong Hian Zin
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Spring-MVC-data-binding-tf3569964s2369.html#a9992427
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to