Validar dos inputText
Buenos dias quiero validar dos inputText, uno es la serie de la Factura y el otro es el numero de Factura, logro hacerlo f:validator pero es por cada uno no se como hacerlo si la serie y el numero de factura esta ya en mi base de datos que no lo guarde que de el error de que ya esta ingresada ese numero de factura. Lo que tengo ahorita es algo asi para cada uno de mis inputText
ValidarFactura.java
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
import javax.faces.validator.FacesValidator;
import programa.utils.Utilidades;
@FacesValidator("programa.validadores.ValidarNumeroFactura")
public class ValidarNumeroFactura implements Validator {
protected static final String SQL_CODIGO_FACTURA =
"select * from factura where no_factura = ?";
public void validate(FacesContext facesContext, UIComponent arg1, Object value) throws ValidatorException
{
String nofacturas = (String)value;
boolean error = false;
Connection conexion = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try
{
conexion = Utilidades.obtenerConexion(Utilidades.conexionPrograma());
pstm = conexion.prepareStatement(SQL_CODIGO_FACTURA);
pstm.setString(1, nofacturas);
rs = pstm.executeQuery();
if(rs.next())
{ error = true; }
}
catch(Exception e)
{ e.printStackTrace(); }
finally
{
try
{
if(rs != null)
{
rs.close();
rs = null;
}
}
catch(Exception eRs)
{ eRs.printStackTrace(); }
try
{
if(pstm != null)
{
pstm.close();
pstm = null;
}
}
catch(Exception ePs)
{ ePs.printStackTrace(); }
try
{
if(conexion != null)
{
conexion.close();
conexion = null;
}
}
catch(Exception eCn)
{ eCn.printStackTrace(); }
}
if(error)
{
FacesMessage fm = new FacesMessage("Ya existe el numero de factura: " + nofacturas, "message");
throw new ValidatorException(fm);
}
}
}
- Inicie sesión o regístrese para enviar comentarios
Comentarios recientes
hace 8 semanas 7 horas
hace 12 semanas 19 horas
hace 19 semanas 4 días
hace 27 semanas 4 días
hace 30 semanas 2 días
hace 31 semanas 6 días
hace 35 semanas 15 horas
hace 35 semanas 16 horas
hace 41 semanas 14 horas
hace 42 semanas 1 día