VALIDATION ERRORS IN STRUTS

Discussions

Web tier: servlets, JSP, Web frameworks: VALIDATION ERRORS IN STRUTS

  1. VALIDATION ERRORS IN STRUTS (3 messages)

    I wanted to change the background color of fields
    that have a validation error to red.
    Can anyone help me with this?. How to or what tags to use to change the background color of that text field.
    I am using the struts validator plugin to do the validations.

    Threaded Messages (3)

  2. RE: VALIDATION ERRORS IN STRUTS[ Go to top ]

    I wanted to change the background color of fieldsthat have a validation error to red.Can anyone help me with this?. How to or what tags to use to change the background color of that text field. I am using the struts validator plugin to do the validations.

    Hi Kiran,
    I've not yet used Validator framework in Struts, but see if this helps:
    Whenever there are validation errors,the ActionErrors is non-empty. To display the error messages on the JSP, you might be using this ActionErrors object, something like -
    <logic:messagesPresent> tag. The same tag you may use when rendering the form controls and if messages are present, change the styleClass of the control e.g.
    <logic:messagesPresent message="true" property="ErrorMsg">
    <html:text property="firstName" styleClass="errorStyle">
    </logic:messagesPresent>
    <logic:messagesNotPresent message="true" property="ErrorMsg">
    <html:text property="firstName" styleClass="normalStyle">
    </logic:messagesNotPresent>

    Hope that helps,
    regards,
    -Prasad
  3. Thanks,[ Go to top ]

    Prasad,

    Thanks for your kind reply. I am using these tags and it works. I was wondering if there was any other efficient technique to identify the errored fields.
    Anyways thanks once again.

    Kiran
  4. Almost the soluttion[ Go to top ]

    http://www.vleite.net/rogel/javascriptValidation.htm

    This article shows how to do client side validation on indexed properties for struts. This is not what you want, but it has a zip file that has something intereting for you. In this zip file there are a lot of changed javascript validation files. These files do not handle the error fields the same way the original files did, it send references for the wrong fields to a new funtion called invalidFields(form, fields, msgs, validationName). The new function recieves references to all the fields that have errors. With that references will can set the color to red.
    fields[i].style.backgroundColor = '#FF0000';

    http://www.vleite.net/rogel/javascriptValidation.htm
    Download the zip file, replace the necessary files and change the invalidFields function to do what you want. This function is in the file validateUtilities.js