You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by bu...@apache.org on 2005/07/04 23:10:33 UTC

DO NOT REPLY [Bug 35600] New: - thought about the ActionRedirect

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=35600>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=35600

           Summary: thought about the ActionRedirect
           Product: Struts
           Version: 1.2.7
          Platform: Other
        OS/Version: other
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Utilities
        AssignedTo: dev@struts.apache.org
        ReportedBy: argol@mailbox.hu


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

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org