• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Tariq Khan
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9495
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Tariq Khan
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9495
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic