struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Newton <newton.d...@yahoo.com>
Subject Re: [S2] Recipe for Action and View
Date Sat, 12 Jul 2008 03:09:49 GMT
Personally I'd either map an action to the input method or differentiate based on GET/POST
requests, but that's just personal preference.

Dave

--- On Fri, 7/11/08, Andreas Mähler <andreas.maehler@stud.uni-karlsruhe.de> wrote:

> From: Andreas Mähler <andreas.maehler@stud.uni-karlsruhe.de>
> Subject: Re: [S2] Recipe for Action and View
> To: user@struts.apache.org
> Date: Friday, July 11, 2008, 10:10 PM
> Hello Gabriel,
> 
> yes, I indeed took that into consideration, but if i am not
> wrong, there 
> are two drawbacks:
> 
> 1: When I create my own base class, and would like to use
> the 
> prepare-method for something else, too, I need to overwrite
> the old 
> method and mustn't forget to call super.prepare() in my
> implementation. 
> IMO, this is a likely source of bugs.
> 
> 2: I would have had to mess with the defaultStack anyway,
> since prepare 
> is located before some other important interceptors (e.g.
> i18n) so I 
> would have lost this functionality by taking an "early
> shortcut".
> 
> The Interceptor was done in 10mins and as far as i could
> test it, it 
> seems to work fine.
> 
> public class SubmitInterceptor implements Interceptor
> {
> 	public static final String INPUT = "input";
> 
> 	public void destroy() {}
> 	public void init() {}
> 
> 
> 	private String paramNames;
> 	
> 	public void setParamNames( String paramNames )
> 	{
> 		this.paramNames = paramNames;
> 	}	
> 	
> 
> 	public String intercept( ActionInvocation ai ) throws
> Exception
> 	{
> 		Map params = ai.getInvocationContext().getParameters();
> 
> 		String[] paramNames = this.paramNames.split(
> "," );
> 		
> 		for( String param : paramNames )
> 		{
> 			if( params.get( param.trim() ) != null )
> 				return ai.invoke();
> 		}
> 		
> 		return INPUT;
> 	}
> }
> 
> I created a new interceptor stack for my webapp that is
> like 
> defaultStack, but with the SubmitInterceptor inserted right
> before 
> conversionError:
> 
> <interceptor-ref name="submit">
> 	<param
> name="paramNames">submit</param>
> </interceptor-ref>
> 
> As for the view, i am currently setting the
> "submit" parameter (as 
> configured to be looked for above) for the Button:
> 
> <s:submit name="submit" label="OK"
> value="true" type="button" />
> 
> Comments and suggestions are welcome :-)
> 
> ~Andreas
> 
> 
> 
> Gabriel Belingueres schrieb:
> > You can also opt for sharing the prepare() code
> through inheritance,
> > meaning that you create a superclass action holding
> the prepare()
> > code, instead of coding a custom interceptor.
> > 
> > 2008/7/11 Andreas Mähler
> <andreas.maehler@stud.uni-karlsruhe.de>:
> >> Thanks for your Answer, Lukasz.
> >>
> >> I already know the PrepareInterceptor and it can
> be used for what I would
> >> like to do. But I consider a special interceptor
> more convinient, since I
> >> intend to use it for more than one pair of view
> and action. (Using
> >> PrepareInterceptor would imply the need to add the
> code to every single
> >> action.)
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org

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


Mime
View raw message