Are there any ways to bind arbitrary element’s css class to model bind state?
<form:form method="post" commandName="authForm" action="authenticate">
<div id="login-error" class="control-group">
<label>Login</label>
<form:input path="name" />
<span class="help-inline"><form:errors path="name" /></span>
</div>
<div class="control-group">
<label>Password</label>
<form:input path="password" />
<span class="help-inline"><form:errors path="password" /></span>
</div>
<input type="submit" />
</form:form>
In this piece of code I need to manage login-error‘s class to control-group when there are no errors and control-group error when there are (the same idea for second control-group).
What’s the common solution here?
Update
Here’s what I need when there’s no bind error:
<div class="control-group"> <!-- !!!!!!!!!!!! -->
<label>Login</label>
<form:input path="name" />
<span class="help-inline"><form:errors path="name" /></span>
</div>
Here’s what I need when there is a bind error:
<div class="control-group error"> <!-- !!!!!!!!!!!! -->
<label>Login</label>
<form:input path="name" />
<span class="help-inline"><form:errors path="name" /></span>
</div>
Looking for solution.
Here’s the solution that just works, but I’m not sure if it’s really good idea: