Everything you've done looks right. What version of Struts are you using,
because I believe the "type" attribute existed in Struts 1.0.x but was
ignored.

Niall

----- Original Message ----- 
From: "Dahnke, Eric (Company IT)" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Wednesday, December 08, 2004 11:19 PM
Subject: Extending ActionMapping to use <set-property>



Hello,

We would like to introduce a custom parameter into all action's
ActionMappings. I've looked at a bunch of examples and threads, but
can't get it to work. Here's the setup:

Struts-config:
--------------
<action-mappings type="com.foo.bar.actions.CustomActionMapping">
    <action path="/uploadSubmit"
type="com.ms.promo.actions.UploadAction"
input="/WEB-INF/web/upload.jsp"
scope="request"
name="uploadForm">
        <set-property property="foo" value="bar" />
        <forward name="display" path="/WEB-INF/web/display.jsp" />
    </action>
</action-mappings>


CustomActionMapping:
--------------------
package com.foo.bar.actions;
import org.apache.struts.action.ActionMapping;
public class CustomActionMapping extends ActionMapping {

    protected String foo;

    public CustomActionMapping() {
        super();
    }
    public String getFoo() {
        return foo;
    }
    public void setFoo(String foo) {
        this.foo = foo;
    }
}


Upload Action:
--------------
public class UploadAction extends Action {
    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
        throws Exception {

        String forward = "display";
        CustomActionMapping cam = (CustomActionMapping) mapping;

        System.out.println("Foo="+cam.getFoo());
}


cam.getFoo() is always null!?!?


A few questions:
----------------

Is the constructor in CustomActionMapping necessary?

Is the casting of the ActionMapping to CustomActionMapping the way to
get at the getter method of the property that is set? If not how do I
get at the set-property?


What am I missing? Thx, Eric
--------------------------------------------------------

NOTICE: If received in error, please destroy and notify sender.  Sender does
not waive confidentiality or privilege, and use is prohibited.


---------------------------------------------------------------------
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