Meaningless Drivel is fun!*
The moose likes Struts and the fly likes Is it LEGAL to access DB from Bean(FormBean of struts) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Is it LEGAL to access DB from Bean(FormBean of struts)" Watch "Is it LEGAL to access DB from Bean(FormBean of struts)" New topic
Author

Is it LEGAL to access DB from Bean(FormBean of struts)

Tariq Khan
Greenhorn

Joined: Jul 25, 2007
Posts: 5
I would like to clarify one doubt that
Can we access DB from our Bean class (FORMBEAN) ?

If not then whats the best practice?

Regards
Muhammad Tariq Khan
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Form Bean as far as I know is just to store your information to be passed from Action to JSP and to store request parameters. Generally a DAO class is used to get data from the database. And the Action should use that database as all the business logic is supposed to be in the action...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Tariq Khan
Greenhorn

Joined: Jul 25, 2007
Posts: 5
Thank you ANKIT,

Yes your are RIGHT that DAO should be used to get the data from DB.
But CAN WE USE DAO INSTANCES IN BEAN CLASS? IS it LEGAL?
Lets say, if I have a condition in which I want to populate some properties on page load then can I use DAO in Beans?

As far as BIZ LOGIC is concerned, I think its best practice to put your biz logic in Business Delegate rather than in Action because Action's primarily use s to handle request, response, session, forwarding and other such operations.

Regards
Muhammad Tariq Khan
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Yes sorry, action is not supposed to contain the business logic. As far as using DAO in the form bean is concerned, its definitely legal. I would still not recommend using DAO in form beans. I'm actually more familiar with struts 2, and there's no form bean in it (there's model driven concept but its a bit different). You said that you want to populate some properties on page load, I cannot understand what you meant by that. If there is a particular use case where you feel that using DAO in the form bean is the best solution, then you can use it...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is it LEGAL to access DB from Bean(FormBean of struts)
 
Similar Threads
html:select and html:options or html:optionsCollection
How to get data back on result page from struts
Struts: access ActionForm bean from JSP
Error compiling a simple servlet !!.... any ideas??
Use form bean in more than one action method