struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Mähler <>
Subject Re: [S2] Recipe for Action and View
Date Sat, 12 Jul 2008 02:10:21 GMT
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 

<interceptor-ref name="submit">
	<param name="paramNames">submit</param>

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 :-)


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 <>:
>> 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:
For additional commands, e-mail:

View raw message