I'm still on my first Struts application, so bear with me...

I'm using EJBGen to generate all my Entity beans (only local interfaces) 
and Session beans (facades with remote interfaces).  One nice byproduct 
of EJBGen is that it also generates Value Objects for each Entity bean 
(I use hand-coded Assemblers to transfer between Value Objects and 
Entity beans).

I wrote a simple little Java program to take as input a directory of 
Value Objects and output Struts Form Beans using the delagation pattern. 
 I currently hardcode the name as (UserValue -> UserFormBase).  This 
provides the necessary extending of the Struts Form (though I extend my 
own BaseForm), but provides no additional functionality (ex: States 
Collection for a dropdown, additional attributes used in the GUI to 
provide information used by the Action and/or Session bean, map a 
particular ValueObject in the parent VO's Collection to another 
attribute for easier GUI manipulation).  So almost all of my *FormBase 
classes are extended by *Form classes to provide that functionality.

I use reset() to provide all 'best guess' defaults.  Within reset(), I 
do not do any checks as to the input path, etc. -- strictly stateless 
initialization.  All other defaults initialization is either done by the 
Session bean by the return of the VO to my form 
(form.setValueObject(vo)), or by statefull modification of attributes in 
the form.

I currently do validation both in the form and action classes -- and 
don't like the way my form validation has gained some statefull tests. 
 I'll likely refactor that back into the action class and only keep 
domain validation in the form (haven't yet had time to review the 
commons validator package).

Jakkampudi, ChandraseKhar wrote:

>Here is what I do. 
>
>User (Generic Value Object)
>UserBean (Extends form bean)
>
>On initial page we have a link to viewUser.do?userId=100
>In the Action class correspoding to viewUser.do, in the perform method we
>have (maybe through an controller or some such)
>
>User newUser = userDAO.getUserDetails("100");
>request.setAttribute("user", User);
>mapping.findForward("user.jsp");
>
>In the user.jsp page,
>User user = (User)request.getAttribute("user"); Use taglibs for this
><html:form action="modifyUser.do">
><html:text property="userName" value="<%=user.getUserName()%>"/>
><html:text property="city" value="<%=user.getCity()%>"/>
>..........
>..........
></html:form>
>
>
>-JC
>
>-----Original Message-----
>From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
>Sent: Thursday, February 14, 2002 6:52 PM
>To: Struts Users Mailing List
>Cc: [EMAIL PROTECTED]
>Subject: Re: ActionForm Defaults/Updates Question
>
>
>
>> In the end, I've just grabbed the Form bean from the pageContext
>>
>
>Pardon my ignorance but can you tell me the syntax in your JSP page to do
>just that above?    I think I'll need to be doing the same thing.
>
>thanks,
>Theron
>
>
>
> 
>
>                    Mark Woon
>
>                    <[EMAIL PROTECTED]        To:     Struts Users Mailing
>List <[EMAIL PROTECTED]>        
>                    nford.EDU>               cc:
>
>                                             Subject:     Re: ActionForm
>Defaults/Updates Question                     
>                    02/14/02 02:22 PM
>
>                    Please respond to
>
>                    Struts Users
>
>                    Mailing List
>
> 
>
> 
>
>
>
>
>[EMAIL PROTECTED] 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:   <
>mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: <
>mailto:[EMAIL PROTECTED]>
>
>
>
>
>--
>To unsubscribe, e-mail:
><mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail:
><mailto:[EMAIL PROTECTED]>
>
>--
>To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
>
>




--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to