• 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

where to validate username password in struts

 
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to check username and password with database . where can i write validations, in Business class or validate()
method or action class.
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check it in validate() method, thats why this method is used..
 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to check whether the username and pasword exists in database. How you can do this in ActionForm's validate() method . Is it possible
 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when to use Actionform's validate() . For which situation we can use validation.xml and validator-rules.xml
 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rajendra Prakash wrote:I want to check whether the username and pasword exists in database. How you can do this in ActionForm's validate() method . Is it possible



yes, its possible.. its like normal validation only, by checking whether the entered user name is there in the database or not..

For which situation we can use validation.xml and validator-rules.xml



validator-rules.xml, is the place where, you specify all your validation rules, like numeric rule, alphanumeric rule.. etc and these rules are used in validation.xml..
 
Ranch Hand
Posts: 93
Python Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do basic validations like empty fields, invalid chars/length in validate() method of ActionForm.

In Action class, call the Business class' method to validate like

Writing database operations in ActionForm and Action classes are not recommended.

And in your business class, do the database implementation with the method returning a boolean or throwing a Exception.
If any error occurs, you can return the forward as


 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you give reason for "Writting database operations in ActionForm and Action classes are not recommended."
I need main reason for writting database operation in business class
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because Struts is an implementation of the Front Controller pattern. It has little or nothing to do with business logic. Have a look here for more information (yes, it's in the 1.3 user guide, but the principal still applies).
 
Ranch Hand
Posts: 479
1
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Consider your Action classes as the one(s) responsible for processing each client request. You can have different classes or even a hierarchy of classes for processing each particular request with all interaction to the persistence/data-access layer being routed though a DAO (an interface) and a DAOImpl (class implementing the persistence methods using the preferred approach, eg:- JDBC, Hibernate, JAXB, CSV etc.).

You provide a layer of abstraction as you can switch between different persistence strategies seamlessly and the remainder of the application would not be affected by this approach. The idea behind application design is to build a system which comprises of different components independent of each other and working in tandem to arrive at the required solution. It becomes all the more better if there is sufficient level of abstraction amongst these individual components so that you can freely make modifications/changes to any particular component and the other components as well as the system, on the whole, is not affected in any manner.

Does that answer your query?

Cheers,
Raj.
 
reply
    Bookmark Topic Watch Topic
  • New Topic