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


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

Re: Validating form inputs?

From Daniel Pitts <newsgroup.nospam@virtualinfinity.net>
Newsgroups comp.lang.java.help
Subject Re: Validating form inputs?
References <ed7f31e9-8a19-46c7-9a7c-ad8aabfb9599@x10g2000pbi.googlegroups.com> <uA4ar.13560$fj7.13111@newsfe20.iad> <9942279.960.1332273017948.JavaMail.geo-discussion-forums@pbbpx7> <578d7f16-cbfb-4718-a639-9e7a312822fc@t2g2000pbg.googlegroups.com>
Message-ID <Bqqar.4635$Ce4.4160@newsfe21.iad> (permalink)
Date 2012-03-21 12:59 -0700

Show all headers | View raw


On 3/21/12 12:02 PM, Davej wrote:
> On Mar 20, 2:50 pm, Lew<lewbl...@gmail.com>  wrote:
>> Daniel Pitts wrote:
>>> Davej wrote:
>>>> I have been thinking about the way I have been validating form
>>>> inputs in the servelet [sic] and wonder if I would be much
>>>> better off using class methods to verify these inputs?
>>
>> What exactly do you mean by "class methods"? Do you mean 'static'
>> member methods?
>>
>>>> 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?
>>
>> Maybe.  It depends on what you mean by "class methods".
>>
>
> Why? I think it could be done either way. If it was a static method is
> would be made generic. If it was non-static it could be an alternate
> set method...
>
> public String ValidateAndSetQuiz1(String q1) //returns error message
> {
>    double score;
>
>    try{
>       score = Double.parseDouble(q1);
>       if ( score<  0 || score>  100.0)
>          return "Value out of allowed range";
>
>    }catch (Exception e)
>    {
>       return "Value is non-numeric";
>    }
>
>    m_quiz1 = score; //accept and set instance variable m_quiz1
>    return null; //signifies that submitted value was accepted
> }
>

Augh, no.

The setter should throw an exception if the value isn't valid.  Also, a 
setter should take in a correctly typed parameter, not a string to be 
parsed.

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