Can anyone explain the mechanism of form pre-population. Since I am a newbie,
my experience bases rather on a try-and-error approach. Related to my
request is also my confusion about differences between generated code by
appfuse:gen and the suggested approach in the online tutorial. 

I came across the problem when I implemented a simple Blog application. I
had a POJO Class "Post" which comprises the fields title, body, created, and
modified. The latter two fields are of type Date and they are not nullable.
The Post JSP form shows only the title and body and allows both to edit. But
when I edit an existing post that has a created/modfied timestamp and hit
the save button, I get an exception coming from the database. For some
reason, the timestamps got lost (set to null). Also, I do not understand why
the action tests pass and the Canoo tests fail.

I figured out that when I make both timestamps available to the JSP form as
hidden information then everything is fine:
        <s:hidden name="post.created" value="%{post.created}"/>
        <s:hidden name="post.modified" value="%{post.modified}"/> 

I was not sure if this is the best solution so I have set up a new project,
created the Post POJO class and run 'mvn appfuse:gen'. Surprisingly, the
resulting PostAction class had a method 'prepare()' which is invoked when I
open the Post list and form page. Then, I removed the date fields from the
form and observed the changes in the database. In contrast to my original
attempt the timestamps were still there. I assume, that the prepare() method
is somehow in charge of this.
 
So, I copied 'prepare()'  to my original PostAction class in the other
project which I implemented by following the tutorial. And guess what, the
'prepare()' method  was not invoked. Why? What's the difference between the
code in the online tutorial and the code generated by appfuse:gen? I was
able to preserve the dates only when I added them to the form as hidden
fields.

Cheers,
Martin
-- 
View this message in context: 
http://www.nabble.com/Struts2%2C-pre-polution--prepare%28%29-in-Action-class-tp16627847s2369p16627847.html
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