Advertisement
Guest User

mbeen/EmployeeRegisterBeen

a guest
Aug 6th, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. package registry.web.mbeans;
  2.  
  3. import org.modelmapper.ModelMapper;
  4. import registry.domain.models.binding.EmployeeRegisterBindingModel;
  5. import registry.domain.models.service.EmployeeRegisterServiceModel;
  6. import registry.service.EmployeeService;
  7.  
  8. import javax.enterprise.context.RequestScoped;
  9. import javax.faces.context.FacesContext;
  10. import javax.inject.Inject;
  11. import javax.inject.Named;
  12. import java.io.IOException;
  13.  
  14. @Named
  15. @RequestScoped
  16. public class EmployeeRegisterBeen {
  17.     private EmployeeRegisterBindingModel registerBindingModel;
  18.  
  19.     private ModelMapper modelMapper;
  20.     private EmployeeService employeeService;
  21.  
  22.     public EmployeeRegisterBeen() {
  23.         registerBindingModel = new EmployeeRegisterBindingModel();
  24.     }
  25.  
  26.     @Inject
  27.     public EmployeeRegisterBeen(ModelMapper modelMapper,
  28.                                 EmployeeService employeeService) {
  29.         this();
  30.         this.modelMapper = modelMapper;
  31.         this.employeeService = employeeService;
  32.     }
  33.  
  34.     public EmployeeRegisterBindingModel getRegisterBindingModel() {
  35.         return registerBindingModel;
  36.     }
  37.  
  38.     public void setRegisterBindingModel(EmployeeRegisterBindingModel registerBindingModel) {
  39.         this.registerBindingModel = registerBindingModel;
  40.     }
  41.  
  42.     public void register() throws IOException {
  43.         System.out.println();
  44.         try {
  45.             employeeService.save(modelMapper.map(registerBindingModel, EmployeeRegisterServiceModel.class));
  46.         }catch (Exception e) {
  47.             e.printStackTrace();
  48.         }
  49.  
  50.         FacesContext.getCurrentInstance().getExternalContext().redirect("/");
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement