struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stjepan Brbot" <stjepan.br...@ht.hr>
Subject Database record create/update STRUTS pattern
Date Fri, 09 Apr 2004 19:11:16 GMT
Hi all,

before I start with this large mail I have to say that I'm fully aware that STRUTS framework
is intended for dealing with presentation and controll flow of application - not for persitance
in database but this is exactly what I'd like to discuss with other experienced STRUTS users
here.

Actually I need something like STRUTS design pattern how to manage presentation/controll flow
of application for process of creating/updating records in database. I'll try to explain how
I did it in my application and like to hear what you can say about it, is my approach good
or there is better/easier way.

1.) I have the list of records on my "persons.jsp" page (btw, retrieved from database using
DAO and ValueList patterns). Each record is represented as a link pointing to "PopulatePersonAction.do"
action and having an ID of particular record as a parameter (link like PopulatePersonAction.do?persId=100).
That are links for updating records. On the bottom of this page there's another link without
parameter pointing to the same PopulatePersonAction.do for creating new record.

2.) PopulatePersonAction tests request parameter for parameter persId and if it receives it
then it does retreives data of this record from database and manually populates PersonForm
(DynaValidatorForm). If PopulatePersonAction does not receive persId, PopulatePersonAction
leaves PersonForm blank for process of inserting new data. In struts-config.xml PopulatePersonAction
is defined *without validation* and *without input page*.

3.) After manually populating PersonForm, PopulatePersonAction forwards flow to "edit-person.jsp"
(if it is process of updating - this form is automatically populated with record's data otherwise
form is blank and ready for creating new record). ID of record is saved in hidden form field.
New or changed data is submitted to another action - DatabaseAction.do.

4) In struts-config.xml file this DatabaseAction is *defined for validation* and *having input=edit-person.jsp*.
If data from edit-person.jsp does not pass the validation, flow is returned to edit-person.jsp
for correcting inserted form data. If DatabaseAction receives persId (from hidden form field
on edit-person.jsp) it knows that it is update process and it updates existing record with
received data otherwise it creates new record. After that DatabaseAction forwards controll
to result.jsp.

5) Result.jsp shows the message about saved record.

---

persons.jsp (list) ---> PopulatePersonAction.do (populate/blank) ---> edit-person.jsp
(html form) ---> DatabaseAction.do (update/create) ---> result.jsp

---

It works but my question is: is it good approach? Is there any easier way of doing that?

Furthermore, I'd like to assemble the complete logic of managing this update/create process
in only one action (it seems that I have to use MappedDispatchAction type of action because
firstly I must not have validation (PopulatePersonAction) and after that I have to use validation
before DatabaseAction).

Thank you if you reached this end, and thank you for your feedback in advance,

Stjepan Brbot

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message