• 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

should not contain any special characters

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone please help as how to proceed ?

I am performing a server side validation , and the Name should not contain any special characters like !#@$%^&*()-+ . except alphabets .

What should be the coding part i should set inside the setter methods of a DTO


Is it appropiate to put this logic inside a Setter Method ?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wouldn't (though I would change the Name property to comply with standard variable naming conventions). A DTO should be nothing more than a transport mechanism.

I'd use a validation framework or some sort of rules engine in the code that implements my business logic.
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

1. You can do the validation in the client side.
2. You can do the validation(business) in the server side within servlet

 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mohamed Inayath wrote:Hi,

1. You can do the validation in the client side.



Of course all this can be is a guide, since there is no way to guarentee validation is run client side in a normal web application. If validation is important (and it usually is) then the server is the place to be doing it.
 
Mohamed Inayath
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Strange..!

If I have to do a sanity check, like for example lenght check, null check or in this case character check.
I have to post a request from the client to server if its invalid then again post the request with a change.

Will it not be feasible to have basic sanity check on the client side and have a pure business check validation at the server side.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
boolean matches= name.matches("!#@$%^]*");

dont use captical for variables, in your case use Name as name.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mohamed Inayath wrote:Strange..!

If I have to do a sanity check, like for example lenght check, null check or in this case character check.
I have to post a request from the client to server if its invalid then again post the request with a change.

Will it not be feasible to have basic sanity check on the client side and have a pure business check validation at the server side.



Yes it will be feasable and probably quite a helpful thing to do. My point is you cannot rely on client side validation alone, because you can't guarentee it is being run.
 
karan wadhwani
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

if ( name.matches("[a-zA-Z]") ) {
// OK
}
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot
 
reply
    Bookmark Topic Watch Topic
  • New Topic