I agree with Richard and Wendy, you probably don't need to actually
instantiate the form, get your bean from somewhere (the ether?) and do a
BeanUtils.copyProperties(dest,source).  This will allow a nice decoupling of
your business code from your web application code.... Alternatively, I would
recommend writing a function to push the data into your form and simply pass
the form as a parameter to it.  

i.e. in your action.execute you could do it like so:

execute (... ActionForm form) {
...
Person person = (Person)Session.getAttribute("person");
MyDataPopulator.populateFooData(form, person);
...

Or

...
Person person = (Person)Session.getAttribute("person");
Object myBean = MyDataGetter.getMyData(person);
BeanUtils.copyProperties(form, myBean)
...

I personally prefer method 2 at this point, but I can see the value of
method 1 (less moving data around).

I actually wrote an app doing all the data access in the forms and, to be
honest, I kinda like it that way too.  The only caveat is that your app and
all your data/business code becomes "Struts-only".  If you can live with
that, then perhaps the road you are pursuing is ok.  

worse is better 

-----Original Message-----
From: Yee, Richard K,,DMDCWEST [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 21, 2003 4:58 PM
To: 'Struts Users Mailing List'
Subject: RE: URGENT: getting a Session Attribute from ActionForm


Mohan,
I agree with Wendy. Prepopulate the form by instantiating it in the action
that forwards to the page that displays the page. Perhaps you can create a
constructor in the ActionForm that takes a userinfo object and invoke this
from your Action.execute method.

Regards,

Richard

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 21, 2003 8:22 AM
To: [EMAIL PROTECTED]
Subject: RE: URGENT: getting a Session Attribute from ActionForm


My aim is to get a session Attribute called as "userinfo" in the ActionForm.
In the ActionForm i have  methods called getAddress,getAddress1,getAddress2.
These are all addresses of this person. So what i want to do is, if all the
info is already present in the db, i want to pre-populate it.If not the user
should beable to fill out the form.

In my getAddress() method i want to do something like this

public Address getAddress(){
  Userinfo userinfo = session.getAttribute("userinfo");
  Person p = userinfo.getPerson();
  Address addr = p.getAddress("Appl Home Address");
  if(addr!=null)
    return addr
   else
   return new Address()
}

similarly
public Address getAddress1(){
  Userinfo userinfo = session.getAttribute("userinfo");
  Person p = userinfo.getPerson();
  Address addr = p.getAddress("Work Address");
  if(addr!=null)
    return addr
   else
   return new Address()

}

This is the reason why i need to access the session Attribute

--Thank you
Mohan
>> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] When the
>> user logons to the system, it takes him to a form. Based on the logon 
>> values, if the user already has filled the form, form should be 
>> populated with values the user can then modify existing
>
>> values save, if not the user can fill in the fresh form and save it.
>> For this i need to get this user logon info in my ActionForm so that 
>> i can write the getters and setters in the ActionForm accordingly
>
> Have you closely examined the struts-example webapp?  It does exactly
> what you're talking about.  Search the archives for 'pre-populate 
> form' and variations, it's a common topic.
>
> Once your user is logged in, I'm guessing you are putting something in
> session scope.  In your Action, you can call
> session.getAttribute("userName") and use that to retrieve the values 
> from wherever they are stored.  Then pre-populate the ActionForm and 
> forward to the 'edit' page.
>
> I would not put user info in a hidden field on the form.  It would
> make it easier for someone to impersonate another user.  (Depends on 
> how sensitive your data is whether that's an issue.)
>
> --
> Wendy Smoak
> Application Systems Analyst, Sr.
> ASU IA Information Resources Management
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED] For 
> additional commands, e-mail: [EMAIL PROTECTED]




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

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

-----------------------------------------
This message and its contents (to include attachments) are the property of Kmart 
Corporation (Kmart) and may contain confidential and proprietary information. You are 
hereby notified that any disclosure, copying, or distribution of this message, or the 
taking of any action based on information contained herein is strictly prohibited. 
Unauthorized use of information contained herein may subject you to civil and criminal 
prosecution and penalties. If you are not the intended recipient, you should delete 
this message immediately.


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

Reply via email to