• 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

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

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic