English 中文(简体)
如何在struts2中配置自定义conversionerrorinterceptor
原标题: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 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;
}}

下面是提到的struts.xml配置。

<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

最佳回答

我看到了一些可能性。

  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.

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

问题回答

暂无回答




相关问题
Getting sitemesh to work with struts2

I m trying to integrate sitemesh into my struts2 app, but i m finding that it s not making any difference and isn t showing any errors (or anything sitemesh related at all) in the logs. I ve started ...

Struts Action Validation

Hey People. I have been recently validating Struts 2 actions. In One of my action class, the save method to be precise must have two id s. That is an assessmenttype id and a course id. this is what is ...

struts2 action not calling properly

On default I want my struts2 app to forward to an action: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"...

How to validate a select tag in struts 2 framework

I am a newbie into programming and i am currently employed as a junior programmer. I am currently having some problems validating the select tags in one of my forms. What i actually trying to do is to ...

Setting the default value in Struts2

I am setting the value(kind of default value) for a drop down select value from action class in a page(given below). When the page loads the value is beig displayed but the other elements of the ...

Localized exceptions (within a Struts2 app)

I am developing a Struts 2 application with support for multiple languages. If one of the domain objects needs to throw an exception, how can it do so in such a way that the error message is no ...

热门标签