質問

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

役に立ちましたか?

解決

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top