Alexander,
This should help you understand applying DAO/DTO patterns in a Struts
app: http://javaboutique.internet.com/tutorials/ApacheDAOs/

Shed.

-----Original Message-----
From: Dahnke, Eric (Company IT) [mailto:[EMAIL PROTECTED]
Sent: Monday, November 29, 2004 11:01
To: Struts Users Mailing List
Subject: RE: Searching pattern/best-practise for forms


That should be:

public EmployeeDTO create(EmployeeDTO employee) 
                                      ^^^^^^^^

Thinking and typing at the same time. ;-)


> -----Original Message-----
> From: Dahnke, Eric (Company IT) 
> Sent: Monday, November 29, 2004 10:56 AM
> To: Struts Users Mailing List
> Subject: RE: Searching pattern/best-practise for forms
> 
> 
> 
> Look into the DAO pattern. Create, for example, an 
> EmployeeDTO (transport object) and an EmployeeDAO class with 
> create(EmployeeDTO employee), update(EmployeeDTO employee), 
> delete(EmployeeDTO employee) and getById(...) - is also a 
> crucial method in the DAO pattern.
> 
> Here's the create method for example:
> 
>     public EmployeeDTO create(EmployeeDTO mailbox) {
>         PreparedStatement stmt = null;
>         try {
>             this.conn = this.getDatabaseConnection("someString");
>             String query = "INSERT " +
>                     "INTO employee " +
>                     "(company_id, first_name, last_name) " +
>                     "VALUES " +
>                     "(?, ?, ?) ";
>             stmt = this.conn.prepareStatement(query);
>             stmt.setInt(1, employee.getCompanyId().intValue());
>             stmt.setString(2, employee.getFirstName());
>             stmt.setString(3, employee.getLastName());
>             stmt.execute();
> 
>             // get the last insert id (sequence)
>             employee.setId(new Integer(this.getSequence()));
> 
>         } catch (Exception e) {
>             e.printStackTrace();
>         } finally {
>             try {
>                 stmt.close();
>                 this.conn.close();
>             } catch (SQLException e) {
>                 e.printStackTrace();
>             }
>         }
>         return employee;
>     }
> 
> Then lookin into the DispatchAction class of struts, and 
> you'll need the BeanUtils class to copy the properties from 
> your ActionForm objects to your transport objects within your 
> struts Actions.
> 
> Stick to the pattern, avoid overly complex things like object 
> caching and persistance unless/until you really need them.
> 
> HTH - Eric
> 
> > -----Original Message-----
> > From: Alexander Czernay [mailto:[EMAIL PROTECTED]
> > Sent: Monday, November 29, 2004 8:30 AM
> > To: [EMAIL PROTECTED]
> > Subject: Searching pattern/best-practise for forms
> > 
> > 
> > I'm searching for a pattern/best-practise for handling standard
> > data-manipulation forms (like list, create, edit, update, delete 
> > functionality) in Struts. I've read about the CRUD 
> > (create/read/update/delete) pattern many times, but 
> couldn't find any 
> > in-depth papers on it.
> > 
> > Is there any recommended how-to/tutorial/paper on this?
> > 
> > Thanks for your help,
> > Alexander
> > 
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > 
> > 
> --------------------------------------------------------
>  
> NOTICE: If received in error, please destroy and notify 
> sender.  Sender does not waive confidentiality or privilege, 
> and use is prohibited. 
>  
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
--------------------------------------------------------
 
NOTICE: If received in error, please destroy and notify sender.  Sender
does not waive confidentiality or privilege, and use is prohibited. 
 

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

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to