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" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; "'Erik Hatcher'" <[EMAIL PROTECTED]> 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:[EMAIL PROTECTED]] Gesendet: Mittwoch, 18. Juli 2001 20:08 An: [EMAIL PROTECTED]; [EMAIL PROTECTED] 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" <[EMAIL PROTECTED]> To: "User-Struts (E-Mail)" <[EMAIL PROTECTED]> 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
Index: FormTag.java =================================================================== RCS file: /home/cvspublic/jakarta-struts/src/share/org/apache/struts/taglib/html/FormTag.java,v retrieving revision 1.13 diff -u -r1.13 FormTag.java --- FormTag.java 2001/05/04 22:21:05 1.13 +++ FormTag.java 2001/07/19 16:47:36 @@ -562,8 +562,13 @@ try { Class clazz = Class.forName(type); bean = clazz.newInstance(); - if (bean instanceof ActionForm) + if (bean instanceof ActionForm) { ((ActionForm) bean).setServlet(servlet); + + // since lookup was called above, its safe to assume that + // that getMappings will not return null + ((ActionForm) +bean).reset(findMapping(getMappings(),getActionMappingName()), +pageContext.getRequest()); + } } catch (Exception e) { throw new JspException (messages.getMessage("formTag.create", type, @@ -763,9 +768,7 @@ } // Look up the application scope collections that we need - ActionMappings mappings = (ActionMappings) - pageContext.getAttribute(Action.MAPPINGS_KEY, - PageContext.APPLICATION_SCOPE); + ActionMappings mappings = getMappings(); ActionFormBeans formBeans = (ActionFormBeans) pageContext.getAttribute(Action.FORM_BEANS_KEY, PageContext.APPLICATION_SCOPE); @@ -779,7 +782,7 @@ // Look up the action mapping we will be submitting to String mappingName = getActionMappingName(); - ActionMapping mapping = mappings.findMapping(mappingName); + ActionMapping mapping = findMapping(mappings, mappingName); if (mapping == null) { JspException e = new JspException (messages.getMessage("formTag.mapping", mappingName)); @@ -806,6 +809,14 @@ type = formBean.getType(); } - - + + private ActionMappings getMappings() { + return (ActionMappings) + pageContext.getAttribute(Action.MAPPINGS_KEY, + PageContext.APPLICATION_SCOPE); + } + + private ActionMapping findMapping (ActionMappings mappings, String mappingName) { + return mappings.findMapping(mappingName); + } }