• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to send data from Action to Bean, to create a record in the database in struts 1.3

 
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, I am Chaitanya, a newbie to struts, I have a doubt regarding how to send data from my Action servlet to the bean so that data is persisted to the database.

I am trying to register a new user. In this process I wrote few classes RegisterForm(form data), RegisterAction(servlet), RegisterBean(data base).

Because the servlet should not have any database code, we need to send the form data to a bean. Anyhow the execute method of RegisterAction servlet is having a ActionForm parameter. Can I send the ActionForm object to RegisterBean class or do it in someother way.

Thank you all in advance. Have a good day.
 
Ranch Hand
Posts: 81
Eclipse IDE Oracle Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have many attributes within the form class, you can send the form as a parameter to the DAO, or else you can get the values from the form class and send only the needed values to the DAO to insert into the database.

~Santhosh
 
chaitanya karthikk
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Santosh.
 
Ranch Hand
Posts: 84
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Passing the form-bean refrence to model layer may not be correct design since form-bean tightly coupled with presentation layer as per the framework design. Most probably all the form-bean properties will not be required for model layer to update in database. Hence, it is better to have modal layer bean class to hold the properties to be updated in database. This can be populated in action class and pass as a parameter to DAO class.
 
chaitanya karthikk
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rajagopal Mani wrote:Hi,

Passing the form-bean refrence to model layer may not be correct design since form-bean tightly coupled with presentation layer as per the framework design. Most probably all the form-bean properties will not be required for model layer to update in database. Hence, it is better to have modal layer bean class to hold the properties to be updated in database. This can be populated in action class and pass as a parameter to DAO class.



Are you saying to again create a bean which holds all form details and then pass the bean to DAO?
 
Rajagopal Mani
Ranch Hand
Posts: 84
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. As mentioned, all the form-bean properties may not be required in all the time. I am not sure about your case. However, this approach will lead maintanability and will separate your model layer from presentation layer.
 
reply
    Bookmark Topic Watch Topic
  • New Topic