struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Emaho, Ghoot" <Gh...@PETROTECHNICS.co.uk>
Subject RE: Automatic Form Validation - A further question
Date Wed, 01 Aug 2001 15:26:16 GMT
I have a solution which is acceptable for now.

I have switched automatic validation off for the form bean, although i
have kept the type/formatting validation logic in the validate method of
the form bean.

I have also added an additional function to the form bean 'isVirgin()'
which my action class calls. This tells the action wether or not it's
the first time round. This is achieved by checking all the form bean
attributes against null - which they are the first time it is created
[providing you dont initialise the private member variables in your form
bean] As this method is in the form bean itself, the action is unaware
of how this is determined, allowing it to change in the future.

If the form is a virgin [excuse the language :)] the action justs
forwards on to the input page. If it's not a virgin, it then calls the
validate method on the form bean, and then does whatever else it needs
to do.

This seems to work well and is portable across all my form beans which
means i have a consistent implementation.

Thanks for your input David

Cheers

Ghoot

> -----Original Message-----
> From: David Winterfeldt [mailto:dwinterfeldt@yahoo.com]
> Sent: 01 August 2001 16:11
> To: struts-user@jakarta.apache.org
> Subject: RE: Automatic Form Validation - A further question
> 
> 
> 
> --- "Emaho, Ghoot" <Ghoot@PETROTECHNICS.co.uk> wrote:
> > Thanks again David.
> > 
> > I have explored extending ActionForm to check for
> > and ignore first time
> > validation. However, it seems from my debug, that
> > the form bean is
> > created a new each time. Can someone else confirm
> > this ?
> If you have the scope of the action set to 'request',
> then the bean is only around for the request.  So it
> would be created each time.  
> 
> > 
> > My further question is this:
> > 
> > If I choose NOT to use automatic validation, and my
> > request goes to the
> > Action first [not the JSP], then what isthe best way
> > to determine in the
> > action that this is the 'first time' for this form
> > bean i.e. it has been
> > created only as a result of the ActionServlet, not
> > because it's coming
> > from the form on a JSP ?
> > 
> > I know you can check the values of the form bean,
> > but this seems a
> > little messy. Any suggestions ?
> I think checking for values is the best way.  How else
> can you tell one instance from another?  The only
> other way I can think of is to have the a class and a
> subclass(es) that doesn't do anything, but represents
> what state the bean is in.
> 
> > 
> > Any help is appreciated, as this is an important
> > issue for us.
> > 
> > Cheers
> > 
> > Ghoot
> > 
> > 
> > > -----Original Message-----
> > > From: David Winterfeldt
> > [mailto:dwinterfeldt@yahoo.com]
> > > Sent: 31 July 2001 18:43
> > > To: struts-user@jakarta.apache.org
> > > Subject: RE: Automatic Form Validation
> > > 
> > > 
> > > 
> > > --- "Emaho, Ghoot" <Ghoot@PETROTECHNICS.co.uk>
> > wrote:
> > > > Thanks for the reply David.
> > > > 
> > > > Yeah, 'action' checking is another way of
> > > > determining wether or not to
> > > > do the validation.
> > > > 
> > > > I guess I was wondering if it was possible to
> > > > configure the Form to
> > > > prevent first time checking ? Would anyone else
> > find
> > > > this useful ?
> > > > 
> > > > Given the recent discussions about preventing
> > direct
> > > > acces to JSP's, it
> > > > seems that the Form validation is designed [in
> > > > default operation] in
> > > > such a way as to expect that you have gone
> > directly
> > > > to the JSP first.
> > > > This is one thing I wouldnt really ever want to
> > do,
> > > > as I prefer all
> > > > requests to go through an action - even if it is
> > > > just to redirect to the
> > > > JSP [call me a control freak! but there area lot
> > of
> > > > others that feel the
> > > > same :) ]
> > > I think it is good to go through the controller if
> > you
> > > really want to keep the view separate.
> > > 
> > > > 
> > > > I wonder if the Auto Validation should
> > accomodate
> > > > the more common
> > > > scenario [certainly in larger applications]
> > where
> > > > you do want to force
> > > > requests thru actions and avoid direct JSP
> > access,
> > > > but avoid first time
> > > > validation. I guess Action Form could be
> > extended to
> > > > provide this, but I
> > > > was hoping it would already be there - as it
> > seems
> > > > quite obvious and
> > > > important. I dont think we should be encouraging
> > > > people to go directly
> > > > to the JSP as part of the Struts framework [just
> > my
> > > > 2p]
> > > You could always have one Action class that
> > handles
> > > all things that are auto-validatded and another
> > for
> > > things that shouldn't be validated.  I'm not sure
> > how
> > > you could have the framework handle something that
> > is
> > > specific for your application unless there was a
> > > parameter that could turn off the auto-validation
> > for
> > > the current request
> > > (org.apache.struts.action.Action.VALIDATE=false).
> > > 
> > > > 
> > > > Picking up on what you mentioned David, about
> > > > handling all 'actions'
> > > > todo with a form in the one Action class. We
> > have
> > > > some sceanrios where
> > > > this is just not practical. What about those
> > > > scenarios ?!
> > > You can of course have as many actions to go with
> > a
> > > form as you want.  I just prefer keeping it to a
> > > minimum.
> > > 
> > > > 
> > > > Thanks anyway David.
> > > > 
> > > > Any other comments ?
> > > > 
> > > > G
> > > > 
> > > > > -----Original Message-----
> > > > > From: David Winterfeldt
> > > > [mailto:dwinterfeldt@yahoo.com]
> > > > > Sent: 31 July 2001 16:46
> > > > > To: struts-user@jakarta.apache.org
> > > > > Subject: RE: Automatic Form Validation
> > > > > 
> > > > > 
> > > > > If you have a variable called action that
> > keeps
> > > > track
> > > > > of what type of action you are performing
> > (create,
> > > > > update, delete), you could check for this in
> > the
> > > > > validate method and only validate on create or
> > > > update.
> > > > >  The Struts example webapp has an action field
> > to
> > > > keep
> > > > > track of this.  I wouldn't do that personally.
> > 
> > > > I've
> > > > > always done my validation from the Action so I
> > > > could
> > > > > use the same action for everything associated
> > with
> > > > a
> > > > > form/table.  For example, delete doesn't need
> > > > > validation or sending someone through the
> > action
> > > > to
> > > > > the view for the first time (as you
> > mentionded). 
> > > > So I
> > > > > don't think there is anything wrong with not
> > using
> > > > the
> > > > > automatic validation.  I think it just depends
> > on
> > > > your
> > > > > design preference.
> > > > > 
> > > > > David
> > > > > 
> > > > > --- "Emaho, Ghoot" <Ghoot@PETROTECHNICS.co.uk>
> > > > wrote:
> > > > > > Some further details on my question:
> > > > > > 
> > > > > > I understand that you can have the request
> > go
> > > > > > straight to the JSP and
> > > > > > avoid the first time validation.
> > > > > > 
> > > > > > This is acceptable in some circumstance, but
> > in
> > > > > > other circumstances you
> > > > > > may wish to have your action do some work
> > before
> > > > > > presenting the page (a
> > > > > > common requirement in more complex
> > > > applications),
> > > > > > and you may wish to
> > > > > > avoid access to any JSP's directly.
> > > > > > 
> > > > > > How then (with this extra clarification) can
> > you
> > > > > > prevent the behaviour
> > > > > > described in the original posting ?
> > 
> === message truncated ===
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Make international calls for as low as $.04/minute with 
> Yahoo! Messenger
> http://phonecard.yahoo.com/
> 

Mime
View raw message