Mapear Campos Del Formulario: Instituto Superior Tecnologico Del Azuay. Prof. Msc. Ing. Soft. Carmen Tacuri V
Mapear Campos Del Formulario: Instituto Superior Tecnologico Del Azuay. Prof. Msc. Ing. Soft. Carmen Tacuri V
Mapear Campos Del Formulario: Instituto Superior Tecnologico Del Azuay. Prof. Msc. Ing. Soft. Carmen Tacuri V
formulario
INSTITUTO SUPERIOR TECNOLOGICO DEL AZUAY. Prof. Msc. Ing. Soft. Carmen Tacuri V.
Mapear campos del formulario
Un formulario se puede mapear directamente a una clase POJO por
ejemplo Usuario, siempre y cuando los campos del formulario coincidan
con los atributos de la clase POJO, entonces los datos se mapean y
poblan.
Para ello trabajamos en el controlador.
INSTITUTO SUPERIOR TECNOLOGICO DEL AZUAY. Prof. Msc. Ing. Soft. Carmen Tacuri V.
Mapear campos del formulario
INSTITUTO SUPERIOR TECNOLOGICO DEL AZUAY. Prof. Msc. Ing. Soft. Carmen Tacuri V.
Mapear campos del formulario
Probamos. El resultado debe ser exactamente igual pero con menor líneas
de código y mas limpio.
INSTITUTO SUPERIOR TECNOLOGICO DEL AZUAY. Prof. Msc. Ing. Soft. Carmen Tacuri V.
Validación de formulario empleando
anotaciones.
El formulario esta ligado a la clase POJO Usuario entonces lo que se hace
es validar esta clase.
Se va a validar usando anotaciones con el API de Valitacion de Java,
Java Bean Validation, a través de estas aplicamos reglas de validación
que ya vienen predefinidas en la plataforma JAVA.
INSTITUTO SUPERIOR TECNOLOGICO DEL AZUAY. Prof. Msc. Ing. Soft. Carmen Tacuri V.
Validación de formulario empleando
anotaciones.
INSTITUTO SUPERIOR TECNOLOGICO DEL AZUAY. Prof. Msc. Ing. Soft. Carmen Tacuri V.
Validación de formulario empleando
anotaciones.
INSTITUTO SUPERIOR TECNOLOGICO DEL AZUAY. Prof. Msc. Ing. Soft. Carmen Tacuri V.
Validación de formulario empleando
anotaciones.
Ahora trabajando en la vista.
INSTITUTO SUPERIOR TECNOLOGICO DEL AZUAY. Prof. Msc. Ing. Soft. Carmen Tacuri V.
Para que funcione el Validar de los
campos, se necesita incorporar la
dependencia spring-boot-starter-validation
En pom.xml
realizamos clic
derecho , Spring,
AddStarters
INSTITUTO SUPERIOR TECNOLOGICO DEL AZUAY. Prof. Msc. Ing. Soft. Carmen Tacuri V.
Para que funcione el Validar de los
campos, se necesita incorporar la
dependencia spring-boot-starter-validation
Marcamos I/O Validations
INSTITUTO SUPERIOR TECNOLOGICO DEL AZUAY. Prof. Msc. Ing. Soft. Carmen Tacuri V.
Para que funcione el Validar de los
campos, se necesita incorporar la
dependencia spring-boot-starter-validation
INSTITUTO SUPERIOR TECNOLOGICO DEL AZUAY. Prof. Msc. Ing. Soft. Carmen Tacuri V.
Para que funcione el Validar de los
campos, se necesita incorporar la
dependencia spring-boot-starter-validation
INSTITUTO SUPERIOR TECNOLOGICO DEL AZUAY. Prof. Msc. Ing. Soft. Carmen Tacuri V.
Para que funcione el Validar de los
campos, se necesita incorporar la
dependencia spring-boot-starter-validation
En el controlador,
cambiamos @Validated
por @Valid
Importamos la librería
Esta es la forma
INSTITUTO SUPERIOR TECNOLOGICO DEL AZUAY. Prof. Msc. Ing. Soft. Carmen Tacuri V. correcta para hacer la
validación.
Para que funcione el Validar de los
campos, se necesita incorporar la
dependencia spring-boot-starter-validation
Ahora en la clase POJO debemos indicar que se necesita validar.
Entonces hay que indicar que campos se requieren que no estén vacíos.
INSTITUTO SUPERIOR TECNOLOGICO DEL AZUAY. Prof. Msc. Ing. Soft. Carmen Tacuri V.
Para que funcione el Validar de los
campos, se necesita incorporar la
dependencia spring-boot-starter-validation
Entonces ahora si la validación funciona.
INSTITUTO SUPERIOR TECNOLOGICO DEL AZUAY. Prof. Msc. Ing. Soft. Carmen Tacuri V.
Ahora mostramos en el formulario los
valores del Request que persisten a pesar
de que se realizó un submit.
Entonces en la vista, empleamos por cada input , value así:
th:value= "${usuario.email}"
INSTITUTO SUPERIOR TECNOLOGICO DEL AZUAY. Prof. Msc. Ing. Soft. Carmen Tacuri V.
Ahora mostramos en el formulario los
valores del Request que se mantienen a
pesar de que se realizó un submit.