You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Holger Wiechert <hw...@iks-gmbh.com> on 2001/07/18 19:44:52 UTC

Access to HttpServletRequest within ActionForm

Hi,

is there a way of getting access within an ActionForm to the request that caused the ActionServlet using this ActionForm?

Something like:

public class MyActionForm extends ActionForm
{
	public MyActionForm
	{
		super();
		HttpServletRequest request = getItSomeHow();
		...
	}
...
}

When the ActionForm is getting created, I need access to some objects that are placed within the current session.
Depending on those values, the ActionForm shall be set up differently.

Thanks in advance,
Holger


[PATCH] Access to HttpServletRequest within ActionForm

Posted by Erik Hatcher <er...@earthlink.net>.
Holgar - I'm posting this to struts-dev rather that struts-user.

I have not tested this modification, but it all compiled fine with the
latest version of Struts in Jakarta's CVS and *should* do the trick.

Attached is the patch to get reset called on new ActionForms instantiated
from the <html:form> tag.   Let me know if there are any problems with it -
it was fairly straightforward, although I did some minor refactoring since
getting the ActionMapping was already done in the lookup, so I created two
private helper methods instead (and modified lookup to use them instead
also).   Perhaps it would have made more sense to store the ActionMapping as
a private instance variable though.

    Erik


----- Original Message -----
From: "Holger Wiechert" <hw...@iks-gmbh.com>
To: <st...@jakarta.apache.org>; "'Erik Hatcher'"
<er...@earthlink.net>
Sent: Thursday, July 19, 2001 12:43 AM
Subject: AW: Access to HttpServletRequest within ActionForm


Thanks for answering.
Since I've got to finish this project "yesterday",
could you please post (and maybe eMail me), when you
submitted the patch?
Thanks in advance,
Holger


-----Ursprüngliche Nachricht-----
Von: Erik Hatcher [mailto:erikhatcher@earthlink.net]
Gesendet: Mittwoch, 18. Juli 2001 20:08
An: struts-user@jakarta.apache.org; hwi@iks-gmbh.com
Betreff: Re: Access to HttpServletRequest within ActionForm


Look at the ActionForm's reset method.   That gives you the request and is
called when its instantiated by the ActionServlet prior to population from
the request.

One note - reset is not currently called when instantiated from the
<html:form> tag unfortunately, but apparently this will be alleviated in the
near future.   I'll submit a patch for this eventually if Craig doesn't get
to it first.

    Erik


----- Original Message -----
From: "Holger Wiechert" <hw...@iks-gmbh.com>
To: "User-Struts (E-Mail)" <st...@jakarta.apache.org>
Sent: Wednesday, July 18, 2001 10:44 AM
Subject: Access to HttpServletRequest within ActionForm


Hi,

is there a way of getting access within an ActionForm to the request that
caused the ActionServlet using this ActionForm?

Something like:

public class MyActionForm extends ActionForm
{
public MyActionForm
{
super();
HttpServletRequest request = getItSomeHow();
...
}
...
}

When the ActionForm is getting created, I need access to some objects that
are placed within the current session.
Depending on those values, the ActionForm shall be set up differently.

Thanks in advance,
Holger



AW: Access to HttpServletRequest within ActionForm

Posted by Holger Wiechert <hw...@iks-gmbh.com>.
Thanks for answering.
Since I've got to finish this project "yesterday",
could you please post (and maybe eMail me), when you
submitted the patch?
Thanks in advance,
Holger


-----Ursprüngliche Nachricht-----
Von: Erik Hatcher [mailto:erikhatcher@earthlink.net]
Gesendet: Mittwoch, 18. Juli 2001 20:08
An: struts-user@jakarta.apache.org; hwi@iks-gmbh.com
Betreff: Re: Access to HttpServletRequest within ActionForm


Look at the ActionForm's reset method.   That gives you the request and is
called when its instantiated by the ActionServlet prior to population from
the request.

One note - reset is not currently called when instantiated from the
<html:form> tag unfortunately, but apparently this will be alleviated in the
near future.   I'll submit a patch for this eventually if Craig doesn't get
to it first.

    Erik


----- Original Message -----
From: "Holger Wiechert" <hw...@iks-gmbh.com>
To: "User-Struts (E-Mail)" <st...@jakarta.apache.org>
Sent: Wednesday, July 18, 2001 10:44 AM
Subject: Access to HttpServletRequest within ActionForm


Hi,

is there a way of getting access within an ActionForm to the request that
caused the ActionServlet using this ActionForm?

Something like:

public class MyActionForm extends ActionForm
{
public MyActionForm
{
super();
HttpServletRequest request = getItSomeHow();
...
}
...
}

When the ActionForm is getting created, I need access to some objects that
are placed within the current session.
Depending on those values, the ActionForm shall be set up differently.

Thanks in advance,
Holger



Re: Access to HttpServletRequest within ActionForm

Posted by Erik Hatcher <er...@earthlink.net>.
Look at the ActionForm's reset method.   That gives you the request and is
called when its instantiated by the ActionServlet prior to population from
the request.

One note - reset is not currently called when instantiated from the
<html:form> tag unfortunately, but apparently this will be alleviated in the
near future.   I'll submit a patch for this eventually if Craig doesn't get
to it first.

    Erik


----- Original Message -----
From: "Holger Wiechert" <hw...@iks-gmbh.com>
To: "User-Struts (E-Mail)" <st...@jakarta.apache.org>
Sent: Wednesday, July 18, 2001 10:44 AM
Subject: Access to HttpServletRequest within ActionForm


Hi,

is there a way of getting access within an ActionForm to the request that
caused the ActionServlet using this ActionForm?

Something like:

public class MyActionForm extends ActionForm
{
public MyActionForm
{
super();
HttpServletRequest request = getItSomeHow();
...
}
...
}

When the ActionForm is getting created, I need access to some objects that
are placed within the current session.
Depending on those values, the ActionForm shall be set up differently.

Thanks in advance,
Holger