开发者

how to configure custom conversionerrorinterceptor in struts2

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 MyConversionErrorI开发者_JAVA技巧nterceptor 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


I see a few possibilities.

  1. The struts2 conversionError interceptor is still going to be called. If you want yours instead of the standard one, you need to define the entire stack yourself, with your interceptor in place of the standard one.
  2. You might want to change the configured name of the custom interceptor so that it is not the same as the standard one. Otherwise, interceptor-ref name="conversionError" may still be pointing to the standard interceptor.
  3. You need to make sure that your new stack is used. You can do that either by declaring it as the default stack, or by referencing the custom stack inside a specific action.

I have a tutorial on custom interceptors in my blog that may be useful: http://ddubbya.blogspot.com/2011/01/creating-custom-struts2-interceptors.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜