Hi Darryl, I'll try my best to clear things up. First of all, in this particular example, Stripes itself doesn't really do much "under the covers" as you say - it just does what you tell it to do. Later on, when you see type converters and formatters, Stripes will be doing more things for you.
That said, in this example I'm just trying to demonstrate how parameter works, and not bother too much with the DAO. To answer your question, indeed by using contact.id as a hidden field, I am updating an existing contact because that's what the DAO does - it receives the Contact object, sees that it has an ID, and does an update. When the ID is null, it creates a new Contact instead. In part III, with JPA/Hibernate and Stripersist, you'll see that what happens is that the ID is actually used to load the existing contact from the database. Then, the submitted values are used to set the updated information on the object before saving it back to the database. The mechanics are different, but the end result is the same: no ID means create, existing ID means update. To answer your following question, yes you could use the contactId parameter to retrieve the contact. And that's probably the more familiar pattern (retrieve from DB / update fields / save). It's just that at this point I'm using a very simple DAO that just accepts Contact objects and figures out what to do with them, so it's simpler to just set the id directly in the object with contact.id. I hope that helps :) Cheers, Freddy http://www.stripesbook.com On Mon, 29 Dec 2008 18:54:52 -0800, "Stoflet Darryl" <[email protected]> said: > Hi Freddy, > > Thanks for the quick reply. The book really rocks, this one little > example > just has me tripped up a bit. > By using contact.id as the hidden field are you just creating a new > Contact > and overwriting the old contact though? I think I validated that is what > is > happening by removing a field in the form (e.g phoneNumber) and then > editing > an existing contact. When I do this using the sample code I loose the > value > in the removed form field (e.g phoneNumber). I don't believe this is the > typical expected behavior for an update. > I am not trying to be a stickler for a particular semantic behavior, just > trying to understand how Stripes does its things under the covers. I have > a > lot of experience with java web development and any time I try a new > framework I seem to spend most of my time understanding how it does what > it > does (that usually pays off once I encounter problems, often self > inflicted > ;-). For the life of me I was unable to figure out how Stripes could load > an > existing Contact using contact.id when the DAO lookup used contactId as > the > field to fetch existing an existing contact. > Would you agree that the proper semantic behavior for an update to a > contact > would be to use contactId as the hidden field (based on the existing > behavior of the action bean)? > I hope I am not way off base here or misunderstanding your intentions in > the > example. > > > On Mon, Dec 29, 2008 at 6:27 PM, Freddy Daoud <[email protected]> wrote: > > > Hi Darryl, > > > > It's very nice to hear that you are enjoying the book. > > > > For the example that you mention: if you look at the bottom of > > page 55(Paper) 65(PDF), you'll see that from the contact list page, > > in contact_list.jsp, the "contactId" parameter is set to the > > corresponding id of the contact on each row of the table, which is > > retrieved using ${contact.id}. Now, when you click on an Update > > link from the contact list, the contactId parameter will be sent > > and used by the getContact() method of ContactBaseActionBean.java > > to retrieve the contact. This allows to prepopulate the form. > > > > At this point, you have the form in contact_form.jsp. When that > > form is submitted, all fields of the contact entered or modified > > by the user are sent, but, as explained on page 56(Paper) 66(PDF), > > we need to resubmit the contact id parameter. The hidden input > > is set to "contact.id" because here we are just resubmitting the > > id that was set in the contact object. We don't need the contactId > > parameter anymore; that was just to prepopulate the form upon > > arrival. > > > > Let me know if that helps. I hope you enjoy the rest of the book! > > > > Cheers, > > Freddy > > http://www.stripesbook.com > > > > On Mon, 29 Dec 2008 17:41:23 -0800, "Stoflet Darryl" <[email protected]> > > said: > > > Hi, > > > > > > I am new to Stripes but have been very intrigued for quite some time. The > > > other java web frameworks have always left a bad taste with me (overly > > > complex, difficult to troubleshoot etc). When the Stripes book from > > > pragprog > > > came out I snapped up a copy. > > > > > > So far I am pleased with the book and am taking my time absorbing it and > > > following along with the examples (with slight customizations for my own > > > better understanding). However I've run into an issue with the first > > > contact > > > form example and I am not sure if its something I did wrong when > > > customizing > > > the example or if there is a typo. On pg 55 there is a hidden form field > > > and > > > its name is set to contact.id. However, the checks within the ActionBean > > > are > > > for contactId, so when an update is submitted that contact is not found > > > and > > > thus not updated. > > > Should the example hidden tag use a name of contactId rather than > > > contact.id > > > ? > > > > > > Btw: The example is also in the freely available forms pdf here: > > > http://media.pragprog.com/titles/fdstr/forms.pdf on page 8. > > > > > > Thanks, > > > Darryl > > > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > > Stripes-users mailing list > > [email protected] > > https://lists.sourceforge.net/lists/listinfo/stripes-users > > ------------------------------------------------------------------------------ _______________________________________________ Stripes-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/stripes-users
