taglib - How to check whether an error happened on a specific property with spring mvc -


i'm using form tag.

<form:form commandname="foo">     <div class="myclass  ">         <label>foo</label>             <form:input path="fooname"/>     </div>         <div class="controls">             <input type="submit" class="btn" value="submit"/>         </div> </form:form> 

question

is there way find out if error happened on specific field?

i aware of <form:erros path="fooname"/> print out error message. after returns true or false based on if error happened on fooname property. need because if error happened can insert css class error next my class

yes, possible:

<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>                              <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>  <form:form commandname="foo">     <spring:bind path="fooname">         <div class="myclass ${status.error ? 'error' : ''}">             <label>foo</label>             <form:input path="fooname"/>         </div>     </spring:bind>     <div class="controls">         <input type="submit" class="btn" value="submit"/>     </div> </form:form> 

when enclose field inside <spring:bind> tag have access implicit variable status of type bindstatus. may use check field has error or not.

you probaly find useful following links:


here way <spring:hasbinderrors> (inside have access errors variable of type errors) work in environment jsp 2.2:

<spring:hasbinderrors name="foo">     <div class="myclass ${errors.hasfielderrors('fooname') ? 'error' : ''}">         <label>foo</label>         <form:input path="fooname"/>     </div> </spring:hasbinderrors> 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -