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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:19:03+00:00 2026-06-11T13:19:03+00:00

I have a simple Spring 3 MVC form using jsp taglibs. I need to

  • 0

I have a simple Spring 3 MVC form using jsp taglibs. I need to add a class based on whether a field within the form has any errors associated with it or not. Here is a snipet of my HTML:

<div class="control-group error"> <!-- HERE: binding.hasErrors() ? "error" : "" -->
    <form:label path="username" cssClass="control-label">User Name</form:label>
    <div class="controls">
        <form:input path="username" cssClass="span3"/>
        <form:errors path="username" cssClass="help-inline" />
    </div>
</div>

So on the first line the class attribute has two classes “control-group” and “error”. I need to add error class only if that field has an error associated with it. I know the WebDataBinder is included in the page somehow, but I don’t know how to access it. Essentially I just want to execute some good old fashion <%= binding.hasError() ? “error” : “” %>, but how do I get access to the binder in the page?

  • 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-11T13:19:04+00:00Added an answer on June 11, 2026 at 1:19 pm

    While this is a little more obscure I think it’s simpler because it’s a single line which is what it would be if I were just using scriplets like any sane Java dev should. Taglibs need to die die die die, then die some more. They are horrible and I can’t believe Java devs still think they actually help and not waste our utter time. PHP developers laugh at us when we use those things.

    <div class="control-group ${requestScope['org.springframework.validation.BindingResult.user'].hasFieldErrors('firstName') ? 'error' : ''}">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple form which is using ASP.NET MVC 3 unobtrusive client side
So I am using Spring MVC 3 with annotations. I have a simple html
Have a simple Spring MVC portlet, and from one of portal pages I have
I have the following class (from a simple Spring tutorial) public class CarValidator implements
I have an extremely simple web application running in Tomcat using Spring 3.0.2, Hibernate
Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
I have a simple html form with two controls: input-text and input-file I need
I am writing a Spring Restful webservices application using Spring MVC. I have used
I'm using MVC to create a few simple CRUD pages. I have a stringly
I'm developing an application in JSP using SimpleFormController with Spring MVC 3.0.2 using Hibernate.

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.