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]

Reply via email to