0

I'm new with GWT and I'm stuck to an issue where to put the validation methods some of them requires asynchronous calls to database my project consists of 2 packages :

client side where the interface and services classes

server side where entities and serviceImpl classes

Do I have to make a third package and place them on it ex: shared ?? or It's Ok to just place them on the client interface classes ex:Login.java

Youans
  • 4,801
  • 1
  • 31
  • 57
  • 1
    You can have both, but for data integrity the validations are server sided i.e. validate a text that should be a number: it must not contain any character different from a number, it must have a restricted length, etc etc. Note that you can *do* all this in client side with JavaScript, but a simple hack trick is to use a proxy to modified the request data in order to check how the server behaves when sending a non-right input. – Luiggi Mendoza Feb 18 '13 at 16:36
  • but won't that be time costly where server side validation will be JVM server compiled while in the same time it have to be scripted call back to client side to inform user that it's a wrong entry – Youans Feb 18 '13 at 16:42
  • Uhm, a 10ms check is really time costly? Well, it would depend about how many data are you sending in your request and what part of the data you (or your user) think is sensitive i.e. in a financial application, you **must** secure the amount inputs, but there's no big deal about validating a description text. – Luiggi Mendoza Feb 18 '13 at 16:43
  • Yes you are right but I think placing them on shared package may solve this issue where shared package is a moderate between client and server side some classes as I read Compiled as server side while other is Scripted as JavaScript Objects and Forgive me I'm just trying to understand what shared package is – Youans Feb 18 '13 at 16:48
  • I don't understand what do you mean with a *shared* package. Where did you get that idea/concept (and please provide a link to it (: )? – Luiggi Mendoza Feb 18 '13 at 16:50
  • Check this out : http://stackoverflow.com/a/5664711/1460591 – Youans Feb 18 '13 at 16:52
  • I understand now, this *shared* is a GWT folder. I'm not a GWT user, so I can't really give you an advice if there should be or not in that folder, but AFAIK validations are mostly on server side. Please check this: [JavaScript: client-side vs. server-side validation](http://stackoverflow.com/q/162159/1065197) – Luiggi Mendoza Feb 18 '13 at 16:59
  • 1
    Server vs client validations aren't really what the question is asking (i.e. not MVC since the C can be on the client or server), but while the server should verify the client's data, client validation is not without merit - it could be handy for instant feedback (i.e. 'invalid date', or 'can't select birthday after today'), and to avoid waiting until save is clicked to keep the client less chatty. The M of MVC is already in shared, putting validation there makes it accessible to both client and server to run as they wish – Colin Alworth Feb 18 '13 at 17:43
  • So you advise me to locate logic validation and M which is the model(Entity Classes) on the shared package and on the other hand use client validation for instant feed back – Youans Feb 18 '13 at 17:59
  • @ColinAlworth OP's looking for an answer indicating the usage (or not) of the shared folder, not a generic-like answer (as me and 2 other people have tried) – Luiggi Mendoza Feb 18 '13 at 22:14

2 Answers2

1

GWT 2.5 comes with support for JSR-303 Bean Validation.

See link:https://developers.google.com/web-toolkit/doc/latest/DevGuideValidation?hl=fr

Gene
  • 616
  • 4
  • 8
0
  • It would be great to completely share the validation code in server and client, but run it in both ends.

    As all said ,good things in client side validation:

  • Immediate feedback without server visit .

  • If client side validation is used, server side validation is still needed

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307