You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by To...@dynegy.com on 2002/02/14 23:03:40 UTC

ActionForm Defaults/Updates Question

Hi all,

I am new to struts and am working on converting an existing system that we
have to Struts to get to know the framework for future development. There
are two questions that really stick out in my mind that I am confused
about.

1. What is the best way to load default values into an ActionForm bean that
will show up the first time a user visits the site and pulls up a jsp page?

2. What is the best way to update a ActionForm bean to output back to the
JSP?

  --Say I have an action that updates fields in that bean. Do I do all this
in the Action class or is there an easier way to do this?


Thanks for your time and help in advance....

Tom



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


Re: ActionForm Defaults/Updates Question

Posted by Mark Woon <mo...@SMI.Stanford.EDU>.
Tom.M.Brunner@dynegy.com wrote:

> 1. What is the best way to load default values into an ActionForm bean that
> will show up the first time a user visits the site and pulls up a jsp page?

You know, this question has come up a bunch of times, but I've never seen any
good responses.

If I've got a form in which users enter contact information, the first time the
user sees it, I'd like to set the default values for the form to whatever I know
about the user.

Since I already have a User object, I would think that the best place to do this
would be in the reset() method of the ActionForm, but there's no way to pass the
ActionForm the User object (or any information that's not part of the form)!  In
the end, I've just grabbed the Form bean from the pageContext and called a
setUser() method so that the reset() method will have something to pull data
from.

Am I missing something?  Is there a better way to do this?

Thanks,
-Mark


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


Re: ActionForm Defaults/Updates Question

Posted by Ted Husted <hu...@apache.org>.
The best approach is to never let the user go directly to a JSP page.
Always pass control through an Action first, which gives you the
opportunity to pre-populate forms, and a number of any other things. 

To prime the pump, you can have the index.jsp forward to an Action.
After that it should always be [action] -> [page] -> [action]

Of course, there is nothing to prevent you from going directly to a JSP,
but in the end, it ends up being more trouble than its worth. Many
people consider it a violation of MVC.

If a form does not need a custom action (yet), you can always use the
standard ForwardAction. 

http://jakarta.apache.org/struts/api-1.0/org/apache/struts/actions/ForwardAction.html

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Java Web Development with Struts.
-- Tel +1 585 737-3463.
-- Web http://www.husted.com/struts/



Tom.M.Brunner@dynegy.com wrote:
> 
> Hi all,
> 
> I am new to struts and am working on converting an existing system that we
> have to Struts to get to know the framework for future development. There
> are two questions that really stick out in my mind that I am confused
> about.
> 
> 1. What is the best way to load default values into an ActionForm bean that
> will show up the first time a user visits the site and pulls up a jsp page?
> 
> 2. What is the best way to update a ActionForm bean to output back to the
> JSP?
> 
>   --Say I have an action that updates fields in that bean. Do I do all this
> in the Action class or is there an easier way to do this?
> 
> Thanks for your time and help in advance....
> 
> Tom
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

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