Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #1639

Re: Validating form inputs?

From Davej <galt_57@hotmail.com>
Newsgroups comp.lang.java.help
Subject Re: Validating form inputs?
Date 2012-03-20 12:56 -0700
Organization http://groups.google.com
Message-ID <d1597b2d-aa47-4b35-8f67-c067a1173e6c@z5g2000pbu.googlegroups.com> (permalink)
References <ed7f31e9-8a19-46c7-9a7c-ad8aabfb9599@x10g2000pbi.googlegroups.com> <uA4ar.13560$fj7.13111@newsfe20.iad>

Show all headers | View raw


On Mar 20, 2:08 pm, Daniel Pitts
<newsgroup.nos...@virtualinfinity.net> wrote:
> On 3/20/12 11:16 AM, Davej wrote:
> > I have been thinking about the way I have been validating form inputs
> > in the servelet and wonder if I would be much better off using class
> > methods to verify these inputs?
>
> > Consider that I am almost always gathering the inputs to instantiate
> > one or more objects, but I gather and validate -- and then
> > instantiate. Maybe I should instantiate an empty object and then use
> > class methods to validate the inputs?
>
> > Thanks
>
> There are a few frameworks that do this in several phases actually. Its
> called binding and validating.
>
> In the binding phase, values are parsed into appropriate data types, and
> stored in the model (Form object as it is sometimes called).  If the
> data can not be parsed, or the model rejects the value immediately, it
> is a binding error.
>
> In the validation phase, the values are checked for correctness. This is
> often a secondary phase because some values are interdependent.
>
> If, after validation, you want to have an immutable object, then you
> could treat your Form object more as a Builder object, and have it
> construct the Real object, which is fully populated and validated.
> Alternatively, you could use the Form object as a "Parameter" object for
> a different Builder class, to keep the concerns of the Form object more
> pure.
>
> I suggest looking into different frameworks, rather than trying to
> roll-your-own. There are a lot of gotchas that can be avoided, and
> boilerplate code you can rid yourself of.  I've had moderate luck with
> Spring Binding.  If you have typical use-cases it works well.  If you
> have more complicated forms, for instance complex dynamic items, then
> there is some shoehorning needed to make it work correctly.
>
> Hope this helps,
> Daniel.

This brings up an issue I would be interested in hearing comments on.
In the curriculum I am pursuing we get an overview of Java and then an
overview of JSP and servelets and then finally in the 3rd semester we
get to frameworks such as Struts. Is this the normal progression? Does
this sequence encourage bad practices or lots of things that need to
be unlearned?

Thanks

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Validating form inputs? Davej <galt_57@hotmail.com> - 2012-03-20 11:16 -0700
  Re: Validating form inputs? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-03-20 12:08 -0700
    Re: Validating form inputs? Lew <lewbloch@gmail.com> - 2012-03-20 12:50 -0700
      Re: Validating form inputs? markspace <-@.> - 2012-03-21 09:24 -0700
      Re: Validating form inputs? Davej <galt_57@hotmail.com> - 2012-03-21 12:02 -0700
        Re: Validating form inputs? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-03-21 12:59 -0700
        Re: Validating form inputs? Lew <lewbloch@gmail.com> - 2012-03-21 13:37 -0700
    Re: Validating form inputs? Davej <galt_57@hotmail.com> - 2012-03-20 12:56 -0700
      Re: Validating form inputs? Lew <lewbloch@gmail.com> - 2012-03-20 13:58 -0700
      Re: Validating form inputs? markspace <-@.> - 2012-03-21 09:30 -0700
  Re: Validating form inputs? Roedy Green <see_website@mindprod.com.invalid> - 2012-03-20 14:28 -0700
    Re: Validating form inputs? Gene Wirchenko <genew@ocis.net> - 2012-03-20 19:16 -0700
      Re: Validating form inputs? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-03-21 17:41 -0300
        Re: Validating form inputs? Gene Wirchenko <genew@ocis.net> - 2012-03-21 14:46 -0700
          Re: Validating form inputs? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-03-21 19:54 -0300
        Re: Validating form inputs? Roedy Green <see_website@mindprod.com.invalid> - 2012-03-22 10:34 -0700
      Re: Validating form inputs? Lew <lewbloch@gmail.com> - 2012-03-21 14:56 -0700
        Re: Validating form inputs? Gene Wirchenko <genew@ocis.net> - 2012-03-21 19:09 -0700
          Re: Validating form inputs? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-03-22 08:36 -0700
            Re: Validating form inputs? Gene Wirchenko <genew@ocis.net> - 2012-03-22 09:40 -0700

csiph-web