-----Original Message-----
From: Brandon Goodin [mailto:[EMAIL PROTECTED]]
Sent: Thursday, November 15, 2001 4:09 PM
To: 'Struts Users Mailing List'
Subject: Extending ActionMapping class


Greetings,

I don't know if what I am doing can be done. I want to use <set-property> in
the struts-config.xml file in my action mapping to provide some custom
properties. The properties will share the same name, but have different
values. Here is my assumption. From what I have read of the Digester it
sounds to me like the addSetProperty will (in short) call the setter of a
particular Class (in this case my extended version of ActionMapping) and
pass the value to the setter that is defined for that property name. I am
collecting the passed values into a Vector in the setter (see below) that
can be called from an Action class using the mapping.getXXX() and do an
iteration and comparison. Anyways, please see my code and commentary below
and if you have the guru-age to enlighten me then I would sure appreciate
it.


----------------------------------------------------------
In my struts-config.xml I have the following for an action mapping:
----------------------------------------------------------
<action parameter="" path="/admin" unknown="false"
type="ws.phase.admin.action.AdminAction">
            <set-property property="aproperty" value="valuea" />
            <set-property property="aproperty" value="valueb" />
            <forward name="login" path="/phaseadmin/login.jsp" redirect="false" />
            <forward name="auth" path="/phaseadmin/main.jsp" redirect="false" />
</action>



----------------------------------------------------------
I have extended to ActionMapping class with the following:
----------------------------------------------------------
import org.apache.struts.action.*;
import org.apache.struts.util.*;

import javax.servlet.ServletException;
import javax.servlet.http.*;

import java.util.*;
/**
 *
 * @author  Administrator
 * @version
 */
public class ExtendedActionMapping extends ActionMapping{

    protected Vector aproperty = new Vector();

    public ExtendedActionMapping () {
        super();
    }

    public void setAproperty(String aproperty){
        this.aproperty.add(aproperty);
    }

    public Vector getAproperty(){
        return aproperty;
    }
}



----------------------------------------------------------
I then want to get the vector from the mapping object. I assume it will go
something like so:
----------------------------------------------------------
-- Previous Action stuff

//This is within the perform method
Vector vec = mapping.getRole();

-- Following Action stuff



----------------------------------------------------------
I am not sure I set up my web.xml file properly to direct all mapping to the
extended mapping class.
I set up my web.xml file to use the exteded ActionMapping class like so:
----------------------------------------------------------

  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>application</param-name>
      <param-value>ApplicationResources</param-value>
    </init-param>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>2</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>2</param-value>
    </init-param>
    <init-param>
      <param-name>validate</param-name>
      <param-value>true</param-value>
    </init-param>
<!-- This is where I insert what I assume will override the default
ActionMapping class to use my extended class -->
    <init-param>
        <param-name>mapping</param-name>
        <param-value>com.mycompany.ExtendedActionMapping</param-value>
    </init-param>
<!-- End of insertion -->
    <load-on-startup>2</load-on-startup>
  </servlet>

----------------------------------------------------------

Thanks,
Brandon Goodin
Phase Communications
P (406)862-2245
F (406)862-0354
http://www.phase.ws


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>




--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to