You must extend the ActionMapping class to include the property you are
wanting to set.  Inside your action, just cast the ActionMapping object to
your custom mapping object.  Inside the deployment descriptor (web.xml), set
the init-param mapping to point to your custom mapping object.

--- start struts-config.xml ---
<action ...>
  <set-property property="myProperty" value="123"/>
  ..
</action>
--- end struts-config.xml ---

--- start web.xml ---
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>mapping</param-name>
      <param-value>MyActionMapping</param-value>
    </init-param>
  </servlet>
--- end web.xml ---

--- start MyActionMapping.java ---
public class MyActionMapping extends ActionMapping {

    protected String myProperty;

    public void setMyProperty(String myProperty) {
        this.myProperty = myProperty;
    }

    public String getMyProperty() {
        return myProperty;
    }
}
--- end MyActionMapping.java ---

--- start MyAction.java ---
public class MyAction extends Action {

    public ActionForward perform(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
                                 throws ServletException {

        /* Cast ActionMapping to MyActionMapping */
        MyActionMapping myMapping = (MyActionMapping)mapping;

        /* do custom processing here */

        return mapping.findForward("success");
    }
}
--- end MyAction.java ---



James Hicks

-----Original Message-----
From: David Holland [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 11, 2001 12:08 PM
To: '[EMAIL PROTECTED]'
Subject: How can I use <set-property property="foo" value="123" /> in
struts-config.xml


How can I use <set-property property="foo" value="123" /> in
struts-config.xml ?

I want to use it in place of forward to store Action configuration info
(set-property is
specified in the dtd).

Tried to add getter & setter to Action descendant - but assignment by
introspection 
didn't seem to work. 

Looked at the source for ActionServlet, and the digester class does appear
to be doing something
with this property, although it looks like it is only looking for a single
instance in an action.

As far as I can tell, either it is not intended for general use or it is
broken.

Any thoughts?

David Holland
[EMAIL PROTECTED]

Reply via email to