This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Struts and the fly likes How to send data from Action to Bean, to create a record in the database in struts 1.3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to send data from Action to Bean, to create a record in the database in struts 1.3" Watch "How to send data from Action to Bean, to create a record in the database in struts 1.3" New topic
Author

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

chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

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.


Love all, trust a few, do wrong to none.
Santhosh ayiappan
Ranch Hand

Joined: Jan 30, 2007
Posts: 80

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

Joined: Sep 15, 2009
Posts: 806

Thank you Santosh.
Rajagopal Mani
Ranch Hand

Joined: Mar 24, 2011
Posts: 84

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

Joined: Sep 15, 2009
Posts: 806

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

Joined: Mar 24, 2011
Posts: 84

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.
 
Don't get me started about those stupid light bulbs.
 
subject: How to send data from Action to Bean, to create a record in the database in struts 1.3