0

I need to override the default conversion messages So, I m trying to make a custom conversion error interceptor for my application which would be called instead of struts default interceptor Below mentioned is the code for that

public class MyConversionErrorInterceptor extends ConversionErrorInterceptor {

private static final long serialVersionUID = 1L;

protected Object getOverrideExpr(ActionInvocation invocation, Object value) {
    ValueStack stack = invocation.getStack();
    return (String)stack.findValue("myproj.item");
}
protected boolean shouldAddError(String propertyName, Object value) {

    return true;
}}

Here is the struts.xml configuration mentioned.

<interceptors >

<interceptor name="conversionError" class="com.celtic.cmvs.webapp.interceptor.MyConversionErrorInterceptor" />

<interceptor-stack name="myDefaultStack">
    <interceptor-ref name="conversionError" />
    <interceptor-ref name="defaultStack"/>
</interceptor-stack>

But it doesn't work. Thanks in advance

4

1 回答 1

2

我看到了几种可能性。

  1. struts2 conversionError 拦截器仍将被调用。如果你想要你的而不是标准的,你需要自己定义整个堆栈,用你的拦截器代替标准的。
  2. 您可能想要更改自定义拦截器的配置名称,使其与标准拦截器不同。否则,interceptor-ref name="conversionError" 可能仍指向标准拦截器。
  3. 您需要确保使用了新堆栈。您可以通过将其声明为默认堆栈或通过在特定操作中引用自定义堆栈来做到这一点。

我的博客中有一个关于自定义拦截器的教程,可能有用:http ://ddubbya.blogspot.com/2011/01/creating-custom-struts2-interceptors.html

于 2011-02-11T15:27:23.027 回答