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

  • SEARCH
  • Home
  • 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 8499707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:44:25+00:00 2026-06-11T00:44:25+00:00

Here is my validate method – @Override public void validate() { errors = new

  • 0

Here is my validate method –

@Override
  public void validate() {
    errors = new HashMap<String, String>();
    if(StringUtil.isBlank(examCode)){
      errors.put("examCode", "Exam code is required");
    }
    if(StringUtil.isBlank(strPaperType)){
      errors.put("paperType", "Paper Type is required");
    }else{
      paperType = PaperType.getPaperTypeByValue(strPaperType);
      if(paperType == null){
        errors.put("paperType", "A valid Paper Type is required");
      }
      if(paperType.equals(PaperType.PRACTICE)){
        if(topicId ==null){
          errors.put("topicId", "Topic Id is required");
        }
      }
    }
    if(StringUtil.isBlank(instructions)){
      errors.put("instructions", "Paper Instructions are required");
    }
  }

‘errors’ is my own map defined in the action. I’m not adding any errors to ‘fieldErrors’. What’s happening is even before entering my ‘validate’ method if I debug ‘fieldErrors’ I see following two entries –

{"id":["Invalid field value for field \"id\"."],"topicId":["Invalid field value for field \"topicId\"."]}

I have no idea from where are they getting added. Here is my struts conf.

<package name="api" extends="json-default" namespace="/api">
    <action name="paper" class="paperApiAction">
      <result name="json" type="json">
        <param name="root">responseDto</param>
      </result>
      <result name="input" type="json">
        <param name="root">fieldErrors</param>
      </result>
    </action>
  </package>

Need help with this. Thanks

  • 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-06-11T00:44:26+00:00Added an answer on June 11, 2026 at 12:44 am

    The “conversionError” interceptor will take type conversion errors and put them into fieldErrors. There are usecases where it’s easier to take it out of the stack; I’m not sure if this is one of them or not.

    Why bother duplicating the fieldErrors map? Even if you just want to have a map for use in your own DTO, why not use the existing validation mechanisms? The difference is minuscule, and a bit more flexible. You could then build the paper type validation into externalized business logic and simplify testing both it, and the action.


    Unrelated, but I find your code difficult to read because of the lack of whitespace. A naive refactoring:

    @Override
    public void validate() {
        errors = new HashMap<String, String>();
    
        if (StringUtil.isBlank(examCode)) {
            errors.put("examCode", "Exam code is required");
        }
    
        if (StringUtil.isBlank(instructions)) {
          errors.put("instructions", "Paper Instructions are required");
        }
    
        if (StringUtil.isBlank(strPaperType)) {
            errors.put("paperType", "Paper Type is required");
        } else {
            validatePaperType();
        }
    }
    
    public void validatePaperType() {
        paperType = PaperType.getPaperTypeByValue(strPaperType);
        if (paperType == null) {
            errors.put("paperType", "A valid Paper Type is required");
            return;
        }
    
        if (paperType.equals(PaperType.PRACTICE) && (topicId == null)) {
            errors.put("topicId", "Topic Id is required");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DLL containing some methods (show, hide and validate). Here is an
Here's the problem, I need to validate the form before submitting in the next
i am trying to validate someone else's code here and they are using the
I’m trying to validate input by using egrep and regex.Here is the line from
I have a regexp to validate file names. Here is it: /[0-9a-zA-Z\^\&\'\@\{\}\[\]\,\$\=\!\-\#\(\)\.\%\+\~\_ ]+$/ It
I know from here that I can pass an ignore option in the jQuery.validate
My issue here is quite simple : i'm trying to use the jQuery validate
Based on the answer provided here , I am attempting to validate whether or
I can't figure out where I'm going wrong here. Trying to validate an email
I'm using a method as explained here: http://iamcam.wordpress.com/2008/01/15/unchecked-checkbox-values/ to get a value even if

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.