I've had success with that using a "Referrer" result, adopted from ww1.x. It
looks something like this. The key is to get the previous location from the
"referer" attribute of the request (REFERER_KEY = "referer"), which contains
the previous result. My version does a little extra, making sure that any
additional parameters supplied to the request also get added to the referrer
location. That's not necessary for everyone, though, so you could just get
rid of that "includeRequestParams" if you want (it's a setting configured as
a result param in xwork.xml).

I've found it extremely useful.

public class ReferrerResult implements Result, WebWorkStatics {
        //~ Static fields/initializers
/////////////////////////////////////////////

        private static final Log log =
LogFactory.getLog(ReferrerResult.class);
        private static final String REFERER_KEY = "referer";
        
        private boolean includeRequestParams = false;
        
        public boolean getIncludeRequestParams(){return
this.includeRequestParams;}
        public void setIncludeRequestParams(boolean
newValue){this.includeRequestParams = newValue;}


        public void execute(ActionInvocation invocation) throws Exception 
        {
                HttpServletResponse response =
ServletActionContext.getResponse();
                HttpServletRequest request =
ServletActionContext.getRequest();
                String location = request.getHeader(REFERER_KEY);
                
                // if "includeRequestParams" is set, then take any
parameters that were
                // on the request and put them in the location URL.
                if (includeRequestParams)
                {
                        URLWrapper urlWrapper = new URLWrapper();
                        urlWrapper.setPage(location);
                        urlWrapper.setRequest(request);
                        urlWrapper.setResponse(response);               
                        // add parameters from request
                        Map params = request.getParameterMap();
                        for (Iterator i = params.keySet().iterator();
i.hasNext();)
                        {
                                String key = (String) i.next();
                                String[] paramValues = (String[])
params.get(key);
                                for (int index = 0; index <
paramValues.length; index++)
                                {
                                        urlWrapper.addParameter(key,
paramValues[index]);
                                }
                        }
                        location = urlWrapper.getURL();         
                }


                if (log.isDebugEnabled()) 
                {
                        log.debug("Redirecting to location " + location);
                }

                response.sendRedirect(location);
        }
        
}

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Jan-Peter Hagenmüller
Sent: Wednesday, December 10, 2003 3:19 PM
To: [EMAIL PROTECTED]
Subject: [OS-webwork] pointing action calling pages

Hi,

any form at any page can call any actions - but how can i point the calling
page with a result desciption like below?

<action name="helpSearchAction" class="action.HelpSearchAction">
     <result name="success" type="dispatcher">  "current page"  </result>
</action>

with no <result...s an empty page is shown, empty "current page" ends with
NPE (see bug report
http://jira.opensymphony.com/secure/ViewIssue.jspa?key=WW-331)

thanks for hints!

jp








-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
Opensymphony-webwork mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork

Reply via email to