Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6032493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:20:33+00:00 2026-05-23T05:20:33+00:00

The scenario of the problem is this 1) We map the struts field values

  • 0

The scenario of the problem is this

1) We map the struts field values to the dtos. The dtos contain integer fields which again are displayed on the screen.

2) Now I enter an incorrect value which gives conversion error for that integer field.

3) At that point in time I decide to quit the page(i.e press cancel), I get a conversion error. This is because the StrutsConversionErrorInterceptor gets called everytime.

Is there any way that I can skip the strutsConversionErrorInterceptor when I am calling a particular method the way we can skip validation using excludeMethods

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:20:33+00:00Added an answer on May 23, 2026 at 5:20 am

    Use this code to override Struts’s StrutsConversionErrorInterceptor…

    public class MyConversionErrorInterceptor extends AbstractInterceptor {
    
        private static final long serialVersionUID = 1L;
    
        public static final String ORIGINAL_PROPERTY_OVERRIDE = "original.property.override";
    
        protected Object getOverrideExpr(ActionInvocation invocation, Object value) {
             ValueStack stack = invocation.getStack();
    
                try {
                    stack.push(value);
    
                    return "'" + stack.findValue("top", String.class) + "'";
                } finally {
                    stack.pop();
                }
        }
    
        @Override
        public String intercept(ActionInvocation invocation) throws Exception {
    
            ActionContext invocationContext = invocation.getInvocationContext();
            Map<String, Object> conversionErrors = invocationContext.getConversionErrors();
            ValueStack stack = invocationContext.getValueStack();
    
            HashMap<Object, Object> fakie = null;
    
            BaseAction baseAction = (BaseAction) invocation.getAction();
            String buttonName = baseAction.getButtonName();
    
            for (Map.Entry<String, Object> entry : conversionErrors.entrySet()) {
                String propertyName = entry.getKey();
                Object value = entry.getValue();
    
                if (shouldAddError(propertyName, value)) {
                    String message = XWorkConverter.getConversionErrorMessage(propertyName, stack);
    
                    Object action = invocation.getAction();
                    if (action instanceof ValidationAware) {
                        ValidationAware va = (ValidationAware) action;
                          if(buttonName.equalsIgnoreCas("Next")){
                              va.addFieldError(propertyName, message);
                          }
                    }
    
                    if (fakie == null) {
                        fakie = new HashMap<Object, Object>();
                    }
                     if(buttonName.equalsIgnoreCas("Next")){
                         fakie.put(propertyName, getOverrideExpr(invocation, value));
                     }
                }
            }
    
            if (fakie != null) {
                // if there were some errors, put the original (fake) values in
                // place right before the result
                stack.getContext().put(ORIGINAL_PROPERTY_OVERRIDE, fakie);
                invocation.addPreResultListener(new PreResultListener() {
                    public void beforeResult(ActionInvocation invocation, String resultCode) {
                        Map<Object, Object> fakie = (Map<Object, Object>) invocation.getInvocationContext().get(ORIGINAL_PROPERTY_OVERRIDE);
    
                        if (fakie != null) {
                            invocation.getStack().setExprOverrides(fakie);
                        }
                    }
                });
            }
    
            return invocation.invoke();
        }
    
        protected boolean shouldAddError(String propertyName, Object value) {
    
            if (value == null) {
                return false;
            }
    
            if ("".equals(value)) {
                return false;
            }
    
            if (value instanceof String[]) {
                String[] array = (String[]) value;
    
                if (array.length == 0) {
                    return false;
                }
    
                if (array.length > 1) {
                    return true;
                }
    
                String str = array[0];
    
                if ("".equals(str)) {
                    return false;
                }
            }
    
            return true;
    
        }
    
    }
    

    You can specify you button names on which you want validation to fire. In above code I have used “Next” in code you can see

    if(buttonName.equalsIgnoreCas(“Next”))

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can you check if this is a browser cache problem? I have this scenario,
Scenario You've got several bug reports all showing the same problem. They're all cryptic
Scenario: Attempting to import many (>100), large(>1M recs) flat-files (csv). Problem: Many records are
I have a problem regarding getting the path of a user control. The scenario
This is my first foray into OO JS, having issues. Ideally in this scenario,
I'm creating a new url infrastructure for my sites, and came across this problem:
Problem: I need to write a function which returns a value for a input
The Scenario: I have an ASP.Net webpage which I intend to use for letting
I have a scenario which is as follows:- A form containing 2 grids. The
I've just come across a pretty strange problem with VS2010 and Script#, which most

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.