I have to implement field level validation in jsp pages using struts1.2 Validator-Framework.
Requirement is like the Error messages should not be displayed in the screen(as normally <html:errors /> tag does),it should be thrown as alert messages.
The user has to alerted if he enters invalid data & focus should be set to same input field with blue background unless until valid input is given to it.
I have tried with below code snippet :
jsp:
<%@taglib uri="/WEB-INF/tld/struts-h
tml.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/tld/struts-b
ean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/tld/struts-l
ogic.tld" prefix="logic"%>
<html:html locale="true">
<body>
<html:errors />
<html:form action="/validity" method="post"
onsubmit="return validateValidForm(this);" focus="myName">
<table>
<tr>
<td><bean:message key="label.groupName" /></td>
<td><html:text property="groupName" maxlength="25" size="26"
onchange="return validateMask(form) && validateMinLength(form);" /></td>
</tr>
<tr>
<td><bean:message key="label.blendedPercenta
ge" /></td>
<td><html:text property="blendedPercentag
e" maxlength="25" size="26"
onchange="return validateInteger(form) && validateIntRange(form);" /></td>
</tr>
<tr>
<td><html:submit property="method">
<bean:message key="btn.press" />
</html:submit></td>
</tr>
</table>
<html:javascript formName="ValidForm" />
</html:form>
</body>
</html:html>
validation.xml
<formset>
<!-- BEGIN WebServer Remote Page -->
<form name="groupDetailsFormBean
">
<field property="groupName" depends="required,mask,min
length">
<arg0 key="label.groupName"/>
<var>
<var-name>mask</var-name>
<var-value>^[a-zA-Z]*$</va
r-value>
</var>
<arg1 key="${var:minlength}" resource="false" />
<var>
<var-name>minlength</var-n
ame>
<var-value>3</var-value>
</var>
</field>
<field property="blendedPercentag
e" depends="required,integer"
>
<arg0 key="label.blendedPercenta
ge" />
</field>
</form>
</formset>
Problem is whenever the user has provided invalid input & he wishes to close the browser.
Normally, the user has to close the "Alert message" & then close the browser.
But I am promoted with second alert message "Invalid Input" after closing which the user is allowed to close the browser.
Sorry i cant provide the screen-short.
Please provide a solution.Is my approach Wright or there exist another one solution for my Field level validationrequirement.
Start Free Trial