You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jon Wall <jw...@yahoo.com> on 2001/12/07 23:37:24 UTC

Re: Struts Design question - followup

Hi Brian - 

Thanks for the responses.  Some more information and
clarification...

> Well, I put data type and required field validation
> only in the bean.

I'm doing this type of validation on the client-side
in JavaScript already.  I prefer to keep it here as
it's not too much work and it's much faster than doing
it server side.  

> You can populate your databean in your action object
> based on DB data since
> the action object is called before the JSP page is
> generated.

I know, but then I have to populate the bean with the
request parameters myself, right?  Struts does the
auto populating before it hands off to me...only it's
not working because the bean hasn't been
"initialized".


thanks..
-jon


--- Brian.Duchouquette@transplace.com wrote:
> 
> Let me try to venture a few responses...
> 
> > But my beans already contain the validation!
> Besides, performing the
> validation in the ActionForm is effectively tying
> business logic (data
> validation) to the web framework dontya think?
> 
> Well, I put data type and required field validation
> only in the bean.
> Validation that is more advanced than that, or based
> on business rules
> should be in your app server (if you have one), or
> in the action object.
> 
> >I need to retrieve the object from the datastore
> (using the id) *before*
> the ActionForm is populated with the request
> parameters.
> 
> You can populate your databean in your action object
> based on DB data since
> the action object is called before the JSP page is
> generated.
> 
> >  the user never submits the form and goes to a
> different section of the
> site. How would I get the bean out of the session?
> 
> All active databeans for a session are stored under
> the key:
> org.apache.struts.action.FORM_BEANS.  You can get
> ahold of this collection
> and clear it out (save the current bean for the page
> you are on).  This is
> sort of a hack, so maybe there is another better way
> to do it..
> 
> Brian
> 
> 
> 
> 
>                                                     
>                                                     
>          
>                     Jon Wall                        
>                                                     
>          
>                     <jwall379@yaho       To:    
> Struts Users Mailing List
> <st...@jakarta.apache.org>        
>                     o.com>               cc:        
>                                                     
>          
>                                          Subject:   
>  Struts Design question                             
>          
>                     12/07/2001                      
>                                                     
>          
>                     03:08 PM                        
>                                                     
>          
>                     Please respond                  
>                                                     
>          
>                     to "Struts                      
>                                                     
>          
>                     Users Mailing                   
>                                                     
>          
>                     List"                           
>                                                     
>          
>                                                     
>                                                     
>          
>                                                     
>                                                     
>          
> 
> 
> 
> 
> I've been lurking on this list for a while, and I
> finally have time to look hard at Struts for a web
> application that I'm working on. I have a coupla
> questions.. 1. This first question I found reference
> to in the archives
>
(http://www.mail-archive.com/struts-user@jakarta.apache.org/msg18281.html)
> but couldn't find an answer. In the application I'm
> working on the business logic is already written and
> is being added to by another team (it's supporting
> other applications besides the web). So I've got a
> whole slew of JavaBeans (100+) already written for
> me,
> but now I'm facing the task of wrapping them in
> ActionForm subclasses, cursing under my breath that
> it
> isn't an interface. I understand that the purpose of
> the ActionForm is as a buffer..perform validation
> and
> all that. But my beans already contain the
> validation!
> Besides, performing the validation in the ActionForm
> is effectively tying business logic (data
> validation)
> to the web framework dontya think? Rules such as no
> invoice numbers under 1000 (Ted's example) should be
> handled by the business logic, and given my
> situation
> (probably a common one), this logic needs to be
> shared
> between applications. I can't go into the server
> system and fit ActionForm into the class heirarchy,
> but I sure could have thrown an interface in there.
> Input on this is appreciated. 2. This has to have
> come
> up before, but I couldn't find any references. All
> of
> my JavaBeans map to persistent components, all of
> which have id's. I've written some actions to
> display
> lists of these components and the like and
> everything
> works great. I also started to try the Add/Edit/Save
> pattern, which occurs everywhere in the app, and I'm
> having a problem with the Save action. The issue is
> that I need to retrieve the object from the
> datastore
> (using the id) *before* the ActionForm is populated
> with the request parameters. What I'd like is to
> have
> the bean populated from the database, and then any
> parameters that are present on the request object
> set
> on the bean, then persist. I can't figure out how to
> initialize the bean to the datastore before it gets
> to
> me in the Action. If I make the ActionForm session
> scoped, it works great...is this the common
> practice?
> If so, how is cleanup performed? IE, user clicks to
> Edit Widget 137, my EditWidgetAction class populates
> WidgetForm and sticks it in the session, the user
> never submits the form and goes to a different
> section
> of the site. How would I get the bean out of the
> session? Any help is appreciated. -jon
> 
> __________________________________________________
> Do You Yahoo!?
> Send your FREE holiday greetings online!
> http://greetings.yahoo.com
> 
> --
> To unsubscribe, e-mail:   <
> mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <
> mailto:struts-user-help@jakarta.apache.org>
> 
> 
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Struts Design question - followup

Posted by Matt Goodall <m....@ntlworld.com>.
On Fri, 2001-12-07 at 22:37, Jon Wall wrote:
> Hi Brian - 
> 
> Thanks for the responses.  Some more information and
> clarification...
> 
> > Well, I put data type and required field validation
> > only in the bean.
> 
> I'm doing this type of validation on the client-side
> in JavaScript already.  I prefer to keep it here as
> it's not too much work and it's much faster than doing
> it server side.  

And what happens when the user has JavaScript turned off?

You need to perform the validation server-side too. Client-side
validation should only really be used to improve usability by avoiding a
trip to the server (as you point out).

Cheers, Matt


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>