Announcement Announcement Module
Collapse
No announcement yet.
'cssErrorClass' How does it work?? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 'cssErrorClass' How does it work??

    hi

    could some one please explain how cssErrorClass detects wether the field has validation errors.

    I was using this and it worked for properties in the command object(Account), but for the properties in Object Person (which is in Account class) it didnt work.

    what i was trying do with the cssErrorClass is just to highlight the input field in yellow color.

    for example when i left my username(property of Account) field empty it worked.
    but when fullName (which is a property of Person class) was left empty it dosnt work

    Code:
    public class Account {
    
    	private int accountId;
    	private String username;
    	private String password;
    	private String authority;
    	private boolean enabled;
    	private Person person;
    
           // setter & getter methods
    }
    Code:
    public class Person {
    	private int personId;
    	private String salutation;
    	private String fullName;
    	private String gender;
    	private Date dateOfBirth;
    	private String ICNo;
    	private String nationality;
    	private String maritalStatus;
    
    	private String email;
    	private String mobile;
    	private String telHome;
    	private String faxHome;
    	private String addressHome;
    
    	private String occupation;
    	private String company;
    	private String telOffice;
    	private String faxOffice;
    	private String addressOffice;
    
    	private String mailingAddress;
    	private boolean subscribedToNewsLetter;
    	private String introducer;
    
    	private Account account;
    
           // setter & getter methods
    }
    Code:
    <form:form action="" method="post" commandName="account">
    	Account Details<br>
    	<table align="center">
    		<tbody>
    			<tr>
    				<td><span class="lable">Username</span></td>
    				<td><form:input path="username" maxlength="32" cssClass="input-text" cssErrorClass="input-text-error" /></td>
    			</tr>
    			<tr>
    				<td><span class="lable">Password</span></td>
    				<td><form:password path="password" maxlength="32" cssClass="input-text" cssErrorClass="input-text-error" /></td>
    			</tr>
    			<tr>
    				<td><span class="lable">Re-enter Password</span></td>
    				<td><input name="confirmPassword" class="input-text"></td>
    			</tr>
    
    		</tbody>
    	</table>
    
    	<br />
    	<br />
    
    	<spring:nestedPath path="person">
    		Personal Details<br>
    		<table align="center">
    			<tbody>
    				<tr>
    					<td><span class="lable">Salutation</span></td>
    					<td><form:select path="salutation">
    						<form:option value="Ms" label="Ms" />
    						<form:option value="Mrs" label="Mrs" />
    					</form:select></td>
    				</tr>
    
    				<tr>
    					<td><span class="lable">Full Name</span></td>
    					<td><form:input path="fullName" maxlength="32" cssErrorClass="input-text-error" /></td>
    				</tr>
    
    				<tr>
    					<td><span class="lable">Gender</span></td>
    					<td align="left"><form:radiobutton path="gender" label="Female" value="Female" /> <form:radiobutton path="gender" label="Male" value="Male" /></td>
    				</tr>
    				<tr>
    					<td><span class="lable">Date of Birth</span></td>
    					<td><form:input path="dateOfBirth" maxlength="32" cssClass="input-text" cssErrorClass="input-text-error" /></td>
    				</tr>
    				<tr>
    					<td><span class="lable">IC/FIN Number</span></td>
    					<td><form:input path="ICNo" maxlength="32" cssClass="input-text" cssErrorClass="input-text-error" /></td>
    				</tr>
    				<tr>
    					<td><span class="lable">Nationality</span></td>
    					<td><form:input path="nationality" maxlength="32" cssClass="input-text" cssErrorClass="input-text-error" /></td>
    				</tr>
    				<tr>
    					<td><span class="lable">Marital Status</span></td>
    					<td><form:input path="maritalStatus" maxlength="32" cssClass="input-text" /></td>
    				</tr>
    				<tr>
    					<td><span class="lable">Email</span></td>
    					<td><form:input path="email" maxlength="32" cssClass="input-text" cssErrorClass="input-text-error" /></td>
    				</tr>
    				<tr>
    					<td><span class="lable">Mobile</span></td>
    					<td><form:input path="mobile" maxlength="32" cssClass="input-text" /></td>
    				</tr>
    				<tr>
    					<td><span class="lable">Tel : Home</span></td>
    					<td><form:input path="telHome" maxlength="32" cssClass="input-text" cssErrorClass="input-text-error" /></td>
    				</tr>
    				<tr>
    					<td><span class="lable">Fax : Home</span></td>
    					<td><form:input path="faxHome" maxlength="32" cssClass="input-text" /></td>
    				</tr>
    				<tr>
    					<td valign="top"><span class="lable">Home Address</span></td>
    					<td align="left"><form:textarea path="addressHome" cols="25" rows="4" cssClass="input-textarea" /></td>
    				</tr>
    			</tbody>
    		</table>
    		<br />
    		<br />
    		Employment Details<br>
    		<table id="personInfo" align="center">
    			<tbody>
    				<tr>
    					<td><span class="lable">Occupation</span></td>
    					<td><form:input path="occupation" cssClass="input-text" cssErrorClass="input-text-error" /></td>
    				</tr>
    				<tr>
    					<td><span class="lable">Company </span></td>
    					<td><form:input path="company" maxlength="32" cssClass="input-text" /></td>
    				</tr>
    				<tr>
    					<td><span class="lable">Tel : Office</span></td>
    					<td><form:input path="telOffice" maxlength="32" cssClass="input-text" /></td>
    				</tr>
    				<tr>
    					<td><span class="lable">Fax : Office</span></td>
    					<td><form:input path="faxOffice" maxlength="32" cssClass="input-text" /></td>
    				</tr>
    				<tr>
    					<td valign="top"><span class="lable">Office Address</span></td>
    					<td align="left"><form:textarea path="addressOffice" cols="25" rows="4" cssClass="input-textarea" /></td>
    				</tr>
    			</tbody>
    		</table>
    
    		<br />
    		<br />
    		Other Details<br>
    		<table align="center">
    			<tbody>
    				<tr>
    					<td><span class="lable">Mailing Address</span></td>
    					<td align="left"><form:select path="mailingAddress">
    						<form:option value="Home" label="Home" />
    						<form:option value="Office" label="Office" />
    					</form:select></td>
    				</tr>
    				<tr>
    					<td><span class="lable">Subscribe To NewsLetter</span></td>
    					<td align="left"><form:checkbox path="subscribedToNewsLetter" value="true" /></td>
    				</tr>
    				<tr>
    					<td valign="top"><span class="lable">Who Introduced You to Aware?</span></td>
    					<td align="left"><form:textarea path="introducer" cols="50" rows="4" cssClass="input-textarea" /></td>
    				</tr>
    			</tbody>
    		</table>
    
    	</spring:nestedPath>
    	
    	<input type="submit" value="Sign Up">
    </form:form>
    controller
    Code:
    	@Override
    	protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    		super.initBinder(request, binder);
    		String[] requiredFields = { "username", "password", "fullName", "gender", "dateOfBirth", "ICNo", "nationality", "email", "telHome",
    				"addressHome" };
    		binder.setRequiredFields(requiredFields);
    		binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("dd-MM-yyyy"), true));
    	}
    please advice me...

    thanks in advance.

  • #2
    Solved

    Hi

    I found the mistake i did, It was in the controllers initBinder method.

    Code:
    String[] requiredFields = { "username", "password", "fullName", "gender", "dateOfBirth", "ICNo", "nationality", "email", "telHome",
    				"addressHome" };
    the propertis of Person class were specified incorrect. so "fullName" should be "person.fullName" , "gender" -> "person.gender"

    the same should happen for the rest of the properties in Person class.

    Comment

    Working...
    X