Commit 6122625c authored by Fabiano Sluzarski's avatar Fabiano Sluzarski
Browse files

Changed messages of cpf error, and added cpf validator.

parent 87b0d82f
......@@ -48,7 +48,7 @@ public class StaffController {
if (staff.getCpf() != null && staff.getCpf().length() > 0 ) {
if (Person.entityManager().createNativeQuery("select * from person where cpf='"+staff.getCpf()+"'", Person.class).getResultList().size() > 0)
bindingResult.addError(new ObjectError("staff.cpf","Staff cpf "+staff.getCpf()+" already exists."));
bindingResult.addError(new ObjectError("staff.cpf","CPF "+staff.getCpf()+" já existe no banco de dados."));
}
if (bindingResult.hasErrors()) {
......
......@@ -37,7 +37,7 @@ public class StudentController {
if (student.getCpf() != null && student.getCpf().length() > 0 ) {
if (Person.entityManager().createNativeQuery("select * from person where cpf='"+student.getCpf()+"'", Person.class).getResultList().size() > 0)
bindingResult.addError(new ObjectError("student.cpf","Student cpf "+student.getCpf()+" already exists."));
bindingResult.addError(new ObjectError("student.cpf","Cpf "+student.getCpf()+" já existe no banco de dados."));
}
if (bindingResult.hasErrors()) {
......
......@@ -17,6 +17,7 @@
<jsp:directive.attribute name="disableFormBinding" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Set to true to disable Spring form binding" />
<jsp:directive.attribute name="type" type="java.lang.String" required="false" rtexprvalue="true" description="Set field type (default 'text', or 'password')" />
<jsp:directive.attribute name="render" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Indicate if the contents of this tag and all enclosed tags should be rendered (default 'true')" />
<jsp:directive.attribute name="cpfvalidator" type="java.lang.Boolean" required="false" rtexprvalue="true" description="" />
<jsp:directive.attribute name="z" type="java.lang.String" required="false" description="Used for checking if element has been modified (to recalculate simply provide empty string value)" />
<c:if test="${empty render or render}">
......@@ -99,9 +100,66 @@
<c:if test="${!empty validationRegex}">
<c:set var="sec_validation_regex" value="regExp : '${validationRegex}', " />
</c:if>
<c:if test="${cpfvalidator}">
<script type="text/javascript">
Spring.addDecoration(new Spring.ElementDecoration({elementId : '_${sec_field}_id', widgetType : 'dijit.form.ValidationTextBox', widgetAttrs : {promptMessage: '${sec_field_validation}', invalidMessage: '${sec_field_invalid}', required : ${required}, ${sec_validation_regex} missingMessage : '${sec_field_required}' }}));
Spring.addDecoration(new Spring.ElementDecoration({elementId : '_${sec_field}_id',
widgetType : 'dijit.form.ValidationTextBox',
widgetAttrs : {promptMessage: '${sec_field_validation}',
invalidMessage: '${sec_field_invalid}',
required : ${required}, ${sec_validation_regex} missingMessage : '${sec_field_required}',
onChange: function valida_cpf() {
var numeros, digitos, soma, i, resultado, digitos_iguais, cpf;
cpf = dijit.byId('_${sec_field}_id').value;
digitos_iguais = 1;
if (!(cpf.length >= 11)) {
alert('CPF Invalido');
return;
}
for (i = 0; !(i >= cpf.length - 1); i++)
if (cpf.charAt(i) != cpf.charAt(i + 1))
{
digitos_iguais = 0;
break;
}
if (!digitos_iguais)
{
numeros = cpf.substring(0,9);
digitos = cpf.substring(9);
soma = 0;
for (i = 10; i > 1; i--)
soma += numeros.charAt(10 - i) * i;
resultado = soma % !(11 >= 2) ? 0 : 11 - soma % 11;
if (resultado != digitos.charAt(0)) {
alert('CPF Invalido');
return;
}
numeros = cpf.substring(0,10);
soma = 0;
for (i = 11; i > 1; i--)
soma += numeros.charAt(11 - i) * i;
resultado = soma % !(11 >= 2) ? 0 : 11 - soma % 11;
if (resultado != digitos.charAt(1)) {
alert('CPF Invalido');
return;
}
return;
}
else {
alert('CPF Invalido');
return;
}
}
}
}
)
);
</script>
</c:if>
<c:if test="${!cpfvalidator}">
<script type="text/javascript">
Spring.addDecoration(new Spring.ElementDecoration({elementId : '_${sec_field}_id', widgetType : 'dijit.form.ValidationTextBox', widgetAttrs : {promptMessage: '${sec_field_validation}', invalidMessage: '${sec_field_invalid}', required : ${required}, ${sec_validation_regex} missingMessage : '${sec_field_required}'}}));
</script>
</c:if>
</div>
<br />
</c:if>
......
......@@ -4,7 +4,7 @@
<jsp:output omit-xml-declaration="yes"/>
<form:create id="fc_br_ufpr_c3sl_sapos_models_people_Professor" modelAttribute="professor" path="/professors/confirmation" render="${empty dependencies}" z="user-managed">
<b>CPF informado já consta no banco de dados. Deseja mesmo cadastrar outro professor com o mesmo cpf?
<b><font color="red">CPF informado já consta no banco de dados. Deseja mesmo cadastrar outro professor com o mesmo cpf? </font>
<br/><br/>
Sim - clique em 'Save' no final da página
<br/>
......@@ -43,7 +43,7 @@
<hr/>
<b>Outros</b>
<p/>
<field:input field="cpf" id="c_br_ufpr_c3sl_sapos_models_people_Professor_cpf" validationRegex="\\d{11}" validationMessageCode="field_invalid_cpf" z="user-managed"/>
<field:input field="cpf" id="c_br_ufpr_c3sl_sapos_models_people_Professor_cpf" cpfvalidator="true" required="true" validationRegex="\\d{11}" validationMessageCode="field_invalid_cpf" z="user-managed"/>
<field:input field="rg" id="c_br_ufpr_c3sl_sapos_models_people_Professor_rg" z="user-managed"/>
<field:input field="emitterRg" id="c_br_ufpr_c3sl_sapos_models_people_Professor_emitterRg" z="user-managed"/>
<field:select field="bank" id="c_br_ufpr_c3sl_sapos_models_people_Professor_bank" itemValue="id" items="${banks}" path="/banks" z="user-managed"/>
......
......@@ -2,7 +2,7 @@
<div xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:field="urn:jsptagdir:/WEB-INF/tags/form/fields" xmlns:form="urn:jsptagdir:/WEB-INF/tags/form" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:spring="http://www.springframework.org/tags" version="2.0">
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<jsp:output omit-xml-declaration="yes"/>
<form:create id="fc_br_ufpr_c3sl_sapos_models_people_Professor" modelAttribute="professor" path="/professors" render="${empty dependencies}" z="user-managed">
<b>Informacoes pessoais</b>
<p/>
......@@ -38,7 +38,7 @@
<hr/>
<b>Outros</b>
<p/>
<field:input field="cpf" id="c_br_ufpr_c3sl_sapos_models_people_Professor_cpf" validationRegex="\\d{11}" validationMessageCode="field_invalid_cpf" z="user-managed"/>
<field:input field="cpf" id="c_br_ufpr_c3sl_sapos_models_people_Professor_cpf" cpfvalidator="true" required="true" validationRegex="\\d{11}" validationMessageCode="field_invalid_cpf" z="user-managed"/>
<field:input field="rg" id="c_br_ufpr_c3sl_sapos_models_people_Professor_rg" z="user-managed"/>
<field:input field="emitterRg" id="c_br_ufpr_c3sl_sapos_models_people_Professor_emitterRg" z="user-managed"/>
<field:select field="bank" id="c_br_ufpr_c3sl_sapos_models_people_Professor_bank" itemValue="id" items="${banks}" path="/banks" z="user-managed"/>
......
......@@ -35,7 +35,7 @@
<hr/>
<b>Outros</b>
<p/>
<field:input field="cpf" id="c_br_ufpr_c3sl_sapos_models_people_Professor_cpf" z="user-managed"/>
<field:input field="cpf" id="c_br_ufpr_c3sl_sapos_models_people_Professor_cpf" cpfvalidator="true" required="true" validationRegex="\\d{11}" validationMessageCode="field_invalid_cpf" z="user-managed"/>
<field:input field="rg" id="c_br_ufpr_c3sl_sapos_models_people_Professor_rg" z="user-managed"/>
<field:input field="emitterRg" id="c_br_ufpr_c3sl_sapos_models_people_Professor_emitterRg" z="user-managed"/>
<field:select field="bank" id="c_br_ufpr_c3sl_sapos_models_people_Professor_bank" itemValue="id" items="${banks}" path="/banks" z="user-managed"/>
......
......@@ -37,7 +37,7 @@
<hr/>
<b>Outros</b>
<p/>
<field:input field="cpf" id="c_br_ufpr_c3sl_sapos_models_people_Staff_cpf" validationRegex="\\d{11}" validationMessageCode="field_invalid_cpf" z="DwNDxIGBCRUWgqZYLUiFz+YUY6k="/>
<field:input field="cpf" id="c_br_ufpr_c3sl_sapos_models_people_Staff_cpf" cpfvalidator="true" required="true" validationRegex="\\d{11}" validationMessageCode="field_invalid_cpf" z="DwNDxIGBCRUWgqZYLUiFz+YUY6k="/>
<field:input field="rg" id="c_br_ufpr_c3sl_sapos_models_people_Staff_rg" z="f0NLxFuMPEVNGVHY15+99p7ctkk="/>
<field:input field="emitterRg" id="c_br_ufpr_c3sl_sapos_models_people_Staff_emitterRg" z="CjyoaKC6Jp+qMHN+oJKOyxC/4+Q="/>
<field:select field="bank" id="c_br_ufpr_c3sl_sapos_models_people_Staff_bank" itemValue="id" items="${banks}" path="/banks" z="sLkdpqWgvA1pCP3WZweDNB+wkc8="/>
......
......@@ -34,7 +34,7 @@
<hr/>
<b>Outros</b>
<p/>
<field:input field="cpf" id="c_br_ufpr_c3sl_sapos_models_people_Staff_cpf" z="DwNDxIGBCRUWgqZYLUiFz+YUY6k="/>
<field:input field="cpf" id="c_br_ufpr_c3sl_sapos_models_people_Staff_cpf" cpfvalidator="true" required="true" validationRegex="\\d{11}" validationMessageCode="field_invalid_cpf" z="DwNDxIGBCRUWgqZYLUiFz+YUY6k="/>
<field:input field="rg" id="c_br_ufpr_c3sl_sapos_models_people_Staff_rg" z="f0NLxFuMPEVNGVHY15+99p7ctkk="/>
<field:input field="emitterRg" id="c_br_ufpr_c3sl_sapos_models_people_Staff_emitterRg" z="CjyoaKC6Jp+qMHN+oJKOyxC/4+Q="/>
<field:select field="bank" id="c_br_ufpr_c3sl_sapos_models_people_Staff_bank" itemValue="id" items="${banks}" path="/banks" z="sLkdpqWgvA1pCP3WZweDNB+wkc8="/>
......
......@@ -39,7 +39,7 @@
<hr/>
<b>Outros</b>
<p/>
<field:input field="cpf" id="c_br_ufpr_c3sl_sapos_models_people_Student_cpf" validationRegex="\\d{11}" validationMessageCode="field_invalid_cpf" z="user-managed"/>
<field:input field="cpf" id="c_br_ufpr_c3sl_sapos_models_people_Student_cpf" cpfvalidator="true" required="true" validationRegex="\\d{11}" validationMessageCode="field_invalid_cpf" z="user-managed"/>
<field:input field="rg" id="c_br_ufpr_c3sl_sapos_models_people_Student_rg" z="user-managed"/>
<field:input field="emitterRg" id="c_br_ufpr_c3sl_sapos_models_people_Student_emitterRg" z="user-managed"/>
<field:select field="bank" id="c_br_ufpr_c3sl_sapos_models_people_Student_bank" itemValue="id" items="${banks}" path="/banks" z="xPtd01IP0ir3GLKvO0tURJ9m2tc="/>
......
......@@ -35,7 +35,7 @@
<hr/>
<b>Outros</b>
<p/>
<field:input field="cpf" id="c_br_ufpr_c3sl_sapos_models_people_Student_cpf" z="user-managed"/>
<field:input field="cpf" id="c_br_ufpr_c3sl_sapos_models_people_Student_cpf" cpfvalidator="true" required="true" validationRegex="\\d{11}" validationMessageCode="field_invalid_cpf" z="user-managed"/>
<field:input field="rg" id="c_br_ufpr_c3sl_sapos_models_people_Student_rg" z="user-managed"/>
<field:input field="emitterRg" id="c_br_ufpr_c3sl_sapos_models_people_Student_emitterRg" z="user-managed"/>
<field:select field="bank" id="c_br_ufpr_c3sl_sapos_models_people_Student_bank" itemValue="id" items="${banks}" path="/banks" z="xPtd01IP0ir3GLKvO0tURJ9m2tc="/>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment