You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Alex Siman <al...@gmail.com> on 2009/08/31 19:05:49 UTC
Interceptor proposal: BeforeValidationInterceptor
In my project I use the following simple but logically useful interceptor.
Maybe Struts community will found its useful too.
BeforeValidationInterceptor.java
--------------------------------
/**
* This interceptor calls {@link BeforeValidationAware#doBeforeValidation()}
* on actions which implement {@link BeforeValidationAware}. This
interceptor
* is very useful for any situation, where you need to clean up or modify
some
* parameters just after all parameters are set but before validation and
* action method invoked.
*
* @see BeforeValidationAware
*
* @author Alex Siman
*/
@SuppressWarnings("serial")
public class BeforeValidationInterceptor extends AbstractInterceptor
{
@Override
public String intercept(ActionInvocation actionInvocation) throws Exception
{
Object action = actionInvocation.getAction();
if (action instanceof BeforeValidationAware)
{
((BeforeValidationAware) action).doBeforeValidation();
}
return actionInvocation.invoke();
}
}
BeforeValidationAware.java
--------------------------------
/**
* @see BeforeValidationInterceptor
*
* @author Alex Siman
*/
public interface BeforeValidationAware
{
public void doBeforeValidation();
}
struts.xml
--------------------------------
<!-- ... -->
<interceptor-stack name="beforeValidationStack">
<!-- ... -->
<interceptor-ref name="params">
dojo\..*,^struts\..*
</interceptor-ref>
<interceptor-ref name="conversionError"/>
<interceptor-ref name="beforeValidation"/>
<interceptor-ref name="validation">
input,back,cancel
</interceptor-ref>
<!-- ... -->
</interceptor-stack>
<!-- ... -->
--
View this message in context: http://www.nabble.com/Interceptor-proposal%3A-BeforeValidationInterceptor-tp25226884p25226884.html
Sent from the Struts - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org
Re: Interceptor proposal: BeforeValidationInterceptor
Posted by Alex Siman <al...@gmail.com>.
Sorry, I forgot about
"com.opensymphony.xwork2.interceptor.PrepareInterceptor".
Alex Siman wrote:
>
> In my project I use the following simple but logically useful interceptor.
> Maybe Struts community will found its useful too.
>
> BeforeValidationInterceptor.java
> --------------------------------
> /**
> * This interceptor calls {@link
> BeforeValidationAware#doBeforeValidation()}
> * on actions which implement {@link BeforeValidationAware}. This
> interceptor
> * is very useful for any situation, where you need to clean up or modify
> some
> * parameters just after all parameters are set but before validation and
> * action method invoked.
> *
> * @see BeforeValidationAware
> *
> * @author Alex Siman
> */
> @SuppressWarnings("serial")
> public class BeforeValidationInterceptor extends AbstractInterceptor
> {
> @Override
> public String intercept(ActionInvocation actionInvocation) throws
> Exception
> {
> Object action = actionInvocation.getAction();
> if (action instanceof BeforeValidationAware)
> {
> ((BeforeValidationAware) action).doBeforeValidation();
> }
>
> return actionInvocation.invoke();
> }
> }
>
>
> BeforeValidationAware.java
> --------------------------------
> /**
> * @see BeforeValidationInterceptor
> *
> * @author Alex Siman
> */
> public interface BeforeValidationAware
> {
> public void doBeforeValidation();
> }
>
>
> struts.xml
> --------------------------------
> <!-- ... -->
> <interceptor-stack name="beforeValidationStack">
> <!-- ... -->
> <interceptor-ref name="params">
> dojo\..*,^struts\..*
> </interceptor-ref>
> <interceptor-ref name="conversionError"/>
> <interceptor-ref name="beforeValidation"/>
> <interceptor-ref name="validation">
> input,back,cancel
> </interceptor-ref>
> <!-- ... -->
> </interceptor-stack>
> <!-- ... -->
>
--
View this message in context: http://www.nabble.com/Interceptor-proposal%3A-BeforeValidationInterceptor-tp25226884p25227304.html
Sent from the Struts - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org