Hi Serge,
> I am still very much interested in the way that it's done in your example.
Just to clear things up about the example you mention. First, the user clicks on
an "Update" link next to a specific entry in the table that displays the
contacts. This link sends the "contactId" parameter to ContactFormActionBean.
Then, the JSP that displays the form contains properties that all start with
"contact.". This calls getContact(), which uses the contactId to retrieve the
contact from the DAO and populate the contact property. A check for null is
there for creating a new contact, in which case the contactId would be null.
Now, the hidden contact.id is a parameter like all the others. The order does
not matter. This is because contactId and contact.id are two different
properties. "contactId" is the link parameter when populating the form, and
"contact.id" is resending the contact id when submitting the form. When the
contact is saved, it contains all the information entered by the user, as well
as the contact id. The DAO figures out from the presence or absence of the id,
whether this is a save or an update. Note that for the purposes of this example,
the DAO implementation is just a simple in-memory Java data structure, not
Hibernate. So "re-hydrating" an object is not necessary. For that, you can use a
pre-binding method as you mentioned, or use a type converter like Stripersist
does, and so on.
Hope that helps. I'm glad you're enjoying the book - thanks for the nice
comment.
Cheers,
Freddy
> What is the binding order when a form is submitted? I came across an example
> in the Stripes book (which is a very nice read) that had a form with a
> hidden field that contained the object that was being edited. When the form
> is submitted for update the action bean form checks to see if the id is
> null, if it's not it reads it from the database and uses that model object
> to back the form.
>
> ActionBean
> ---------------------------------
>
> private Integer contactId;
> public Integer getContactId() {
> return contactId;
> }
> public void setContactId(Integer id) {
> contactId = id;
> }
>
> public Contact getContact() {
> if (contactId != null) {
> return contactDao.read(contactId);
> }
> return contact;
> }
>
> Is there any guarantee that the hidden form value (contactId) would be set
> on the ActionBean before getContact is called? Is it the form order that
> determines this? I have no idea.
> Thanks for all the replies. Freedy, contact.id and contact.firstName are both
> parameters at the same level. I totally understand the parameters being
> bound before the event being called. I also understand why you put a
> setContactId on the actionBean ¿ it seems that stripes will collapse
> contact.id to contactId and try to set it as a property on your actionbean
> before calling getContact().setId().
>
> Form to be submitted for Update
>
> <s:form beanclass="ContactFormActionBean">
> <div><s:hidden name="contact.id"/></div>
> <table>
> <tr>
> <td>FirstName:</td>
> <td><s:text name="contact.firstName"/></td>
> </tr>
> </table>
> .....
> </form>
>
> I am probably missing something in your explanation about the parameters. If
> I changed the code like this ¿ would it make any difference? Notice I
> changed the order of the hidden field. If the answer is contact.id parameter
> will always be set before the contact.firstname I definitely missed
> something in your explanation. I thought that maybe properties of the
> actionBean are set before nested objects .. but I can¿t really confirm.
>
> <s:form beanclass="ContactFormActionBean">
> <table class="form">
> <tr>
> <td>FirstName:</td>
> <td><s:text name="contact.firstName"/></td>
> </tr>
> </table>
> <s:hidden name="contact.id"/></div>
> ......
> </form>
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users