You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Paul Benedict (JIRA)" <ji...@apache.org> on 2006/12/02 22:25:58 UTC
[jira] Resolved: (STR-2512) thought about the ActionRedirect
[ http://issues.apache.org/struts/browse/STR-2512?page=all ]
Paul Benedict resolved STR-2512.
--------------------------------
Resolution: Not A Problem
> thought about the ActionRedirect
> --------------------------------
>
> Key: STR-2512
> URL: http://issues.apache.org/struts/browse/STR-2512
> Project: Struts 1
> Issue Type: Improvement
> Components: Core
> Environment: Operating System: other
> Platform: Other
> Reporter: Korompai Attila
> Assigned To: Paul Benedict
> Priority: Minor
>
> Hi!
> Just some thought about the ActionRedirect class.
> It's realy useful, but i miss 2 really simple feature.
> - it should handle all kind of parameter, specially int and long (used for id's)
> , that
> would make the code cleaner (no conversion)
> - the programmer should also be able to set or unset redirect (i speak about the
> ActionForward#setRedirect).
> Not very important anyway, but can come handy.
> have a nice day,
> Attila
> PS: For my part, i use something like that:
> //-------------------------------
> ActionForwardParameters afp = new ActionForwardParameters(mapping);
> afp.add(USER_ID,userId);
> afp.setRedirect(true);
> return afp.forward("deleteuser");
> //-------------------------------
> public class ActionForwardParameters
> {
> private Map params = new HashMap();
> private boolean redirect = false;
> private ActionMapping mapping;
>
> public ActionForwardParameters(ActionMapping mapping)
> {
> this.mapping = mapping;
> }
>
> public ActionForwardParameters add(Hashtable parametersValues)
> {
> for(Iterator i =parametersValues.keySet().iterator();i.hasNext();)
> {
> String key = (String) i.next();
> params.put(key,(String) parametersValues.get(key));
> }
>
> return this;
> }
> public ActionForwardParameters add(String key, String value)
> {
> params.put(key,value);
> return this;
> }
>
> public ActionForwardParameters add(String key, Object value)
> {
> return add(key, value.toString());
> }
> public ActionForwardParameters add(String key, int value)
> {
> return add(key, Integer.toString(value)) ;
> }
> public ActionForwardParameters add(String key, long value)
> {
> return add(key, Long.toString(value));
> }
> public ActionForwardParameters add(String key, double value)
> {
> return add(key, Double.toString(value));
> }
> public ActionForwardParameters add(String key, float value)
> {
> return add(key, Float.toString(value));
> }
> public ActionForwardParameters add(String key, boolean value)
> {
> return add(key, Boolean.toString(value));
> }
>
> public void setRedirect(boolean redirect)
> {
> this.redirect = redirect;
> }
> public ActionForward forward(String name)
> {
> ActionForward forward = mapping.findForward(name);
> StringBuffer path = new StringBuffer(forward.getPath());
>
> boolean hasParam = true;
> if(path.indexOf("?") == -1) hasParam = false;
>
> Iterator iter = params.entrySet().iterator();
> if (iter.hasNext())
> {
> Map.Entry entry = (Map.Entry) iter.next();
> if(hasParam) path.append("&");
> else path.append("?");
> path.append(entry.getKey() + "=" + entry.getValue());
> while (iter.hasNext())
> {
> entry = (Map.Entry) iter.next();
> path.append("&" + entry.getKey() + "=" + entry.getValue());
> }
> }
>
> ActionForward newForward = new ActionForward(path.toString());
> newForward.setRedirect(redirect);
> return newForward;
> }
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/struts/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira