struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Billy Ng" <kwo...@earthlink.net>
Subject extending Action problems
Date Fri, 04 Jul 2003 09:05:34 GMT
I make a mistake on extending the Action.  I have the following code to set the parameters
in the perform() to the setters.  At first,  I wanted whichever the classes that extends ActionBase
can get the parameters by simply calling the getters.  However, the Action is a singleton,
the instance variables will be used by all actions.  Anybody can give me suggestion to make
the getters to return the mapping, form, req, and resp as local variables?

Thanks!

public class ActionBase extends Action {

    private ActionMapping mapping;
    private ActionForward actionForward;
    private ActionForm form;
    private HttpServletRequest req;
    private HttpServletResponse resp;
    private String view;

    protected void process() throws Exception {}

    public ActionForward perform(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest req,
                                 HttpServletResponse resp) {

        setActionMapping();
        setActionForm(data);
        setRequest(req);
        setResponse(resp);
        process();
   }

    protected void setActionMapping(ActionMapping mapping) {
        this.mapping = mapping;
    }

    protected ActionMapping getActionMapping() {
        return this.mapping;
    }

    protected void setRequest(HttpServletRequest req) {
        this.req = req;
    }

    protected HttpServletRequest getRequest() {
        return this.req;
    }

    protected void setResponse(HttpServletResponse resp) {
        this.resp = resp;
    }

    protected HttpServletResponse getResponse() {
        return this.resp;
    }
}

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message