| 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: 779
|
|
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: 70
|
|
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: 779
|
|
|
Thank you Santosh.
|
 |
Rajagopal Mani
Ranch Hand
Joined: Mar 24, 2011
Posts: 80
|
|
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: 779
|
|
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: 80
|
|
|
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.
|
 |
 |
|
|
subject: How to send data from Action to Bean, to create a record in the database in struts 1.3
|
|
|