Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ss.controladores;
- import com.ss.editores.MyPropertyEditorRegistrar;
- import com.ss.modelo.FechaEspecial;
- import com.ss.repositorios.FechaEspecialRepositorio;
- import com.ss.services.TransactionServiceImpl;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.validation.BindingResult;
- import org.springframework.validation.Validator;
- import org.springframework.web.bind.WebDataBinder;
- import org.springframework.web.bind.annotation.InitBinder;
- import org.springframework.web.bind.annotation.ModelAttribute;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- @Controller
- @RequestMapping(value = "/fechasEspeciales")
- public class FechaEspecialControlador {
- @Autowired
- private TransactionServiceImpl transactionService;
- @Autowired
- private MyPropertyEditorRegistrar myPropertyEditorRegistrar;
- @Autowired
- private Validator validator;
- public FechaEspecialControlador(MyPropertyEditorRegistrar myPropertyEditorRegistrar) {
- this.myPropertyEditorRegistrar = myPropertyEditorRegistrar;
- }
- @InitBinder
- public void initBinder(WebDataBinder binder) {
- myPropertyEditorRegistrar.registerCustomEditors(binder);
- }
- @RequestMapping(value = "/crear", method = RequestMethod.POST)
- public String crear(@ModelAttribute FechaEspecial fechaEspecial, BindingResult result, Model model) {
- try {
- validator.validate(fechaEspecial, result);
- if(!result.hasErrors()) {
- transactionService.crear(fechaEspecial);
- model.addAttribute("fechaEspecial", new FechaEspecial());
- }
- }
- catch(Exception e) {
- model.addAttribute("mensaje", "Ocurrió un error al tratar de crear la nueva fecha especial");
- }
- return "/fechasEspeciales/formulario.jsp";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement