Return-Path: Delivered-To: apmail-jakarta-struts-user-archive@jakarta.apache.org Received: (qmail 43510 invoked by uid 500); 2 Aug 2001 00:23:53 -0000 Mailing-List: contact struts-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk Reply-To: struts-user@jakarta.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list struts-user@jakarta.apache.org Received: (qmail 43503 invoked from network); 2 Aug 2001 00:23:53 -0000 Received: from mms.tumbleweed.com (64.41.172.2) by h31.sny.collab.net with SMTP; 2 Aug 2001 00:23:53 -0000 Received: from 172.17.1.51 by mms.tumbleweed.com with SMTP (Tumbleweed MMS SMTP Relay (MMS v4.7)); Wed, 01 Aug 2001 17:24:19 -0700 X-Server-Uuid: 538e6a8c-0f42-11d4-9400-000102237308 Message-ID: <062601c11ae9$5b7ceb20$c77ba8c0@frmt1.sfba.home.com> From: "Martin Cooper" To: struts-user@jakarta.apache.org References: Subject: Re: Automatic Form Validation - A further question Date: Wed, 1 Aug 2001 17:17:14 -0700 MIME-Version: 1.0 X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 X-WSS-ID: 17764238228366-01-01 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N Why not just have two action mappings which refer to the same action, one which specifies the form and one which does not? Then your "first time" action can go through the mapping which doesn't specify the form. In this case, the form parameter in the call to perform() will be null, so you can easily detect this case. Backing up in this thread a bit, I'm not clear on what your "first time" scenario is. If the form validation is being invoked, then a request must have been submitted with data to populate the form. What is it about this first request that makes you want to ignore the data for the request? -- Martin Cooper ----- Original Message ----- From: "Emaho, Ghoot" To: Sent: Wednesday, August 01, 2001 8:26 AM Subject: RE: Automatic Form Validation - A further question 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" 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" > > 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" > > > > 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/ >