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 8794321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:14:08+00:00 2026-06-13T23:14:08+00:00

I used ajax validation to validate the following <tr> <td width=20 style=’color: red’> <img

  • 0

I used ajax validation to validate the following

   <tr>
      <td width="20" style='color: red'>
         <img src="images/icon-star.png" width="16" height="16" />
      </td>
      <td id="lblCustomBillNo" style="width: 15%" class="searchCriteriaCellLbl">
         The custom Bill Number
      </td>
      <td width="5" class="searchCriteriaCellLbl">:</td>
      <td class="searchCriteriaCellVal">
          <s:textfield id="customBillNo" name="customBillNo" size="20" maxlength="24" style="width: 200px" />
      </td>
      <td class="errorFlag" style="color: red" valign="middle">
          <s:fielderror fieldName="customBillNo" />
      </td>
  </tr>
  <tr>
      <td width="20" style='color: red'>
        <img src="images/icon-star.png" width="16" height="16" />
      </td>
      <td id="lblBillNo" style="width: 15%" class="searchCriteriaCellLbl">
         <s:property value="%{getText('billNo')}" />
      </td>
      <td width="5" class="searchCriteriaCellLbl">:
      </td>
      <td class="searchCriteriaCellVal">
          <s:textfield label="billNo" id="billNo" name="billNo" size="20" maxlength="24" style="width: 200px" />
      </td>
      <td class="errorFlag" style="color: red" valign="middle">
          <s:fielderror fieldName="billNo" />
      </td>
  </tr>
  <tr>
      <td width="20" style='color: red'>
        <img src="images/icon-star.png" width="16" height="16" />
      </td>
     <td id="lblCarrierNo" style="width: 15%" class="searchCriteriaCellLbl">
        The carrier Number
     </td>
     <td width="5" class="searchCriteriaCellLbl">:
     </td>
     <td class="searchCriteriaCellVal">
        <s:textfield label="carrierNo" id="carrierNo" name="carrierNo" size="20" maxlength="24" style="width: 200px" />
     </td>
     <td class="errorFlag" style="color: red" valign="middle">
        <s:fielderror fieldName="carrierNo" />
     </td>
 </tr>

I use the following internationalization for errors in golbal i18n file

errors.required=${getText(fieldName)} requireddd

and this validation file

 <validators>      
     <field name="customBillNo">
        <field-validator type="requiredstring" short-circuit="true">
           <param name="trim">true</param>
           <message key="errors.required" />
        </field-validator>
     </field>
     <field name="billNo">
      <field-validator type="required" short-circuit="true">
        <message key="errors.required" />
       </field-validator>
     </field>
     <field name="carrierNo">
       <field-validator type="required" short-circuit="true">
          <message key="errors.required" />
       </field-validator>
     </field>
   </validators>

and i put this javascript to use ajax validation

      function validate(){

            //document.all.loading.style.display = 'block';

            var searchUrl = 'AddEnteringApproval_approval';

            var params = '';

            var elemArray = document.mainForm.elements;
            for (var i = 0; i < elemArray.length;i++)
            {
                var element = elemArray[i];

                var elementName= element.name;
                if(elementName=='formAction')
                    continue;
                params += '&' + elementName+'='+ encodeURIComponent(element.value);
            }

            params += '&struts.enableJSONValidation=true&struts.validateOnly=true';

            createXmlHttpObject(); // this is my function that prepare ajax

            sendRequestPost(http_request,searchUrl,false,params);

            postValidation();

    }

    function postValidation() {
       var form = $('#mainForm');

       var text = http_request.responseText;

       //clear previous validation errors, if any
       StrutsUtils.clearValidationErrors(form);
       alert(text)
       //get errors from response
       //var text = request.responseText;
       var errorsObject = StrutsUtils.getValidationErrors(text);

       //show errors, if any
       if(errorsObject.fieldErrors)
       {
         StrutsUtils.showValidationErrors(form, errorsObject);
       }
       else
       {
         //good to go, regular submit
         form.submit();
       }
    }


       /*  This is one of the functions that doesn't work using the simple theme, so I redefined it.
        This can be changed to clear the previous errors, as it does in the commented example
        cleaning the errors on divErrors.
        As I am just showing the messages with alerts I don't need to clear anything,
        but the method still need to be redefined, even if it is empty.
     */

   StrutsUtils.clearValidationErrors = function(form, errors) {
        //clear the div errors
        //$('#divErrors').empty();
    }


    /* This method is responsible to show the messages.
       The original versions works with the xhrml and css-xhtml theme but doesn't work with the simple theme
       so I override the method with another implementation that shows the messages using alerts.
       You can change the implementation to show the messages as you want,
       but as the previous method this has to be redefined.
     */

    StrutsUtils.showValidationErrors = function(form, errors) {

        if(errors.fieldErrors)
        {alert((errors.fieldErrors))
             for(var fieldName in errors.fieldErrors)
             { 
                 alert("errors.fieldErrors[fieldName]   " + errors.fieldErrors[fieldName]);

               for(var i = 0; i < errors.fieldErrors[fieldName].length; i++)
               {
                   alert('Field ->' + fieldName + '\nError -> ' + errors.fieldErrors[fieldName][i]);
               }
             }
        }
    };

but when i execute the code i get no organized JSON text i showed in alert message box, the field name is not like the one in the error message, the second field name is missing, the third field name is cut (i.e. carrierNo becomes rNo ).

can you help me. i want the field name in the JSON error match the error message text

I just figured out what is the problem, but i don’t know why it happens and why.
it always remove the first 6 characters. why this happens

enter image description here

  • 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-13T23:14:09+00:00Added an answer on June 13, 2026 at 11:14 pm

    well I figured out the problem.
    it was a but in org.apache.struts2.interceptor.validation.JSONValidationInterceptor

    it removes the 6 first characters because of this incomplete if statement

    sb.append((validationAware instanceof ModelDriven) ? ((String)fieldError.getKey()).substring(6) : (String)fieldError.getKey());
    

    this error is fuond in struts 2.1.8

    it should be like this

    sb.append(((validationAware instanceof ModelDriven)) && (fieldErrorKey.startsWith("model.")) ? fieldErrorKey.substring(6) : fieldErrorKey);
    

    it was corrected in later struts releses. i corrected the problem. and i thought i have to share the information for people who faces the problem.

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

Sidebar

Related Questions

I'm making a signup form in which i've used following function for validate signup
Thus for used ajax enabled wcf services to get records from DB and display
I've always used ajax to load() the contents of a DOM element but now
whenever I've used Ajax, I've used asp.net Ajax update panel and script manager provided
I have used ajax auto completeextender in my program well its works fine no
I made some ajax sites in the past where I used ajax to get
I am making a web page in that I have used Ajax calendar to
I am developing a site using asp.net MVC. I have used AJAX for paging,sorting
In jQuery is there a callback that can be used when an ajax request
No javascript\AJAX is to be used.

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.