Guest User

Untitled

a guest
Feb 23rd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.58 KB | None | 0 0
  1. <form th:action="${modelo.id>0}? @{/costos/admin/modelo/modificar}:@{/costos/admin/modelo}" method="post" th:object="${modelo}">
  2. <div class="row">
  3. <div class="col-xs-12 col-sm-8">
  4. <label >Modelo</label>
  5. <input type="hidden" th:field="*{id}">
  6. <div class="input-group">
  7. <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
  8. <input class="form-control input-lg" type="text" th:field="*{modelo}">
  9. </div>
  10. <div class="alert alert-danger" th:if="${#fields.hasErrors('modelo')}" th:errors="*{modelo}" ></div>
  11. </div>
  12. <div class="col-xs-12 col-sm-4">
  13. <label >Categoria</label>
  14. <select class="form-control input-lg" th:field="*{categoria}">
  15. <option th:each="cat:${categorias}"
  16. th:value="${cat.id}"
  17. th:text="${cat.categoria}"> </option>
  18. </select>
  19. </div>
  20.  
  21. </div>
  22. <br>
  23. <div class="row">
  24. <div class="col-xs-12 text-right">
  25. <a type="button" class="btn btn-danger BOTON_LIMPIAR" href="/index"> <span class=" glyphicon glyphicon-remove"></span> Cancelar</a>
  26. <button type="submit" class="btn btn-success"> <span class="glyphicon glyphicon-floppy-save"></span> <span th:text="${modelo.id>0}? @{Modificar}:@{Guardar}"></span></button>
  27. </div>
  28. </div>
  29. </form>
  30.  
  31. @Entity
  32. @Table(name = "modelo")
  33. @XmlRootElement
  34. @NamedQueries({
  35. @NamedQuery(name = "Modelo.findAll", query = "SELECT m FROM Modelo m")
  36. , @NamedQuery(name = "Modelo.findById", query = "SELECT m FROM Modelo m WHERE m.id = :id")
  37. , @NamedQuery(name = "Modelo.findByModelo", query = "SELECT m FROM Modelo m WHERE m.modelo = :modelo")
  38. , @NamedQuery(name = "Modelo.findByIdTamano", query = "SELECT m FROM Modelo m WHERE m.idTamano = :idTamano")
  39. , @NamedQuery(name = "Modelo.findByEspesorPastilla", query = "SELECT m FROM Modelo m WHERE m.espesorPastilla = :espesorPastilla")
  40. , @NamedQuery(name = "Modelo.findByEspesorBoton", query = "SELECT m FROM Modelo m WHERE m.espesorBoton = :espesorBoton")
  41. , @NamedQuery(name = "Modelo.findByLineasOMm", query = "SELECT m FROM Modelo m WHERE m.lineasOMm = :lineasOMm")
  42. , @NamedQuery(name = "Modelo.findByCentroOFrente", query = "SELECT m FROM Modelo m WHERE m.centroOFrente = :centroOFrente")
  43. , @NamedQuery(name = "Modelo.findByDiametroEspalda", query = "SELECT m FROM Modelo m WHERE m.diametroEspalda = :diametroEspalda")
  44. , @NamedQuery(name = "Modelo.findByRectificado", query = "SELECT m FROM Modelo m WHERE m.rectificado = :rectificado")
  45. , @NamedQuery(name = "Modelo.findByVelocidad", query = "SELECT m FROM Modelo m WHERE m.velocidad = :velocidad")
  46. , @NamedQuery(name = "Modelo.findByMaterialEfecto", query = "SELECT m FROM Modelo m WHERE m.materialEfecto = :materialEfecto")
  47. , @NamedQuery(name = "Modelo.findByFotoCelda", query = "SELECT m FROM Modelo m WHERE m.fotoCelda = :fotoCelda")
  48. , @NamedQuery(name = "Modelo.findByInclinacion", query = "SELECT m FROM Modelo m WHERE m.inclinacion = :inclinacion")
  49. , @NamedQuery(name = "Modelo.findByDiametroPata", query = "SELECT m FROM Modelo m WHERE m.diametroPata = :diametroPata")
  50. , @NamedQuery(name = "Modelo.findByEspesorPata", query = "SELECT m FROM Modelo m WHERE m.espesorPata = :espesorPata")
  51. , @NamedQuery(name = "Modelo.findByAlturaPata", query = "SELECT m FROM Modelo m WHERE m.alturaPata = :alturaPata")
  52. , @NamedQuery(name = "Modelo.findByObservaciones", query = "SELECT m FROM Modelo m WHERE m.observaciones = :observaciones")
  53. , @NamedQuery(name = "Modelo.findByCavidadDiametro", query = "SELECT m FROM Modelo m WHERE m.cavidadDiametro = :cavidadDiametro")
  54. , @NamedQuery(name = "Modelo.findByCavidadProfundidad", query = "SELECT m FROM Modelo m WHERE m.cavidadProfundidad = :cavidadProfundidad")
  55. , @NamedQuery(name = "Modelo.findByFigura", query = "SELECT m FROM Modelo m WHERE m.figura = :figura")})
  56. public class Modelo implements Serializable {
  57.  
  58. @Basic(optional = false)
  59. @NotNull()
  60. @Size(min = 1, max = 20)
  61. @Column(name = "modelo")
  62. private String modelo;
  63.  
  64. @Size(max = 50)
  65. @Column(name = "materialEfecto")
  66. private String materialEfecto;
  67. @Size(max = 20)
  68. @Column(name = "fotoCelda")
  69. private String fotoCelda;
  70. @Size(max = 20)
  71. @Column(name = "inclinacion")
  72. private String inclinacion;
  73. @Size(max = 400)
  74. @Column(name = "Observaciones")
  75. private String observaciones;
  76. @Size(max = 50)
  77. @Column(name = "figura")
  78. private String figura;
  79.  
  80. private static final long serialVersionUID = 1L;
  81. @Id
  82. @GeneratedValue(strategy = GenerationType.IDENTITY)
  83. @Basic(optional = false)
  84. @Column(name = "id")
  85. private Integer id;
  86. @Column(name = "idTamano")
  87. private Integer idTamano;
  88. // @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
  89. @Column(name = "espesorPastilla")
  90. private Float espesorPastilla;
  91. @Column(name = "espesorBoton")
  92. private Float espesorBoton;
  93. @Column(name = "lineasOMm")
  94. private Float lineasOMm;
  95. @Column(name = "centroOFrente")
  96. private Float centroOFrente;
  97. @Column(name = "diametroEspalda")
  98. private Float diametroEspalda;
  99. @Column(name = "rectificado")
  100. private Boolean rectificado;
  101. @Column(name = "velocidad")
  102. private Integer velocidad;
  103. @Column(name = "diametroPata")
  104. private Float diametroPata;
  105. @Column(name = "espesorPata")
  106. private Float espesorPata;
  107. @Column(name = "alturaPata")
  108. private Float alturaPata;
  109. @Column(name = "cavidadDiametro")
  110. private Float cavidadDiametro;
  111. @Column(name = "cavidadProfundidad")
  112. private Float cavidadProfundidad;
  113. @JoinTable(name = "relacionmodelos", joinColumns = {
  114. @JoinColumn(name = "idModelo", referencedColumnName = "id")}, inverseJoinColumns = {
  115. @JoinColumn(name = "idModeloRelacionado", referencedColumnName = "id")})
  116. @ManyToMany
  117. private Collection<Modelo> modeloCollection;
  118. @ManyToMany(mappedBy = "modeloCollection")
  119. private Collection<Modelo> modeloCollection1;
  120.  
  121. @JoinColumn(name = "idcategoria_producto", referencedColumnName = "id")
  122. @ManyToOne
  123. private CategoriaProducto categoria;
  124. @JoinColumn(name = "agujas", referencedColumnName = "id")
  125. @ManyToOne
  126. private Refaccion agujas;
  127. @JoinColumn(name = "guia", referencedColumnName = "id")
  128. @ManyToOne
  129. private Refaccion guia;
  130.  
  131. public Modelo() {
  132. }
  133.  
  134. public Modelo(Integer id) {
  135. this.id = id;
  136. }
  137.  
  138. public Modelo(Integer id, String modelo) {
  139. this.id = id;
  140. this.modelo = modelo;
  141. }
  142.  
  143. public Integer getId() {
  144. return id;
  145. }
  146.  
  147. public void setId(Integer id) {
  148. this.id = id;
  149. }
  150.  
  151.  
  152. public Integer getIdTamano() {
  153. return idTamano;
  154. }
  155.  
  156. public void setIdTamano(Integer idTamano) {
  157. this.idTamano = idTamano;
  158. }
  159.  
  160. public Float getEspesorPastilla() {
  161. return espesorPastilla;
  162. }
  163.  
  164. public void setEspesorPastilla(Float espesorPastilla) {
  165. this.espesorPastilla = espesorPastilla;
  166. }
  167.  
  168. public Float getEspesorBoton() {
  169. return espesorBoton;
  170. }
  171.  
  172. public void setEspesorBoton(Float espesorBoton) {
  173. this.espesorBoton = espesorBoton;
  174. }
  175.  
  176. public Float getLineasOMm() {
  177. return lineasOMm;
  178. }
  179.  
  180. public void setLineasOMm(Float lineasOMm) {
  181. this.lineasOMm = lineasOMm;
  182. }
  183.  
  184. public Float getCentroOFrente() {
  185. return centroOFrente;
  186. }
  187.  
  188. public void setCentroOFrente(Float centroOFrente) {
  189. this.centroOFrente = centroOFrente;
  190. }
  191.  
  192. public Float getDiametroEspalda() {
  193. return diametroEspalda;
  194. }
  195.  
  196. public void setDiametroEspalda(Float diametroEspalda) {
  197. this.diametroEspalda = diametroEspalda;
  198. }
  199.  
  200. public Boolean getRectificado() {
  201. return rectificado;
  202. }
  203.  
  204. public void setRectificado(Boolean rectificado) {
  205. this.rectificado = rectificado;
  206. }
  207.  
  208. public Integer getVelocidad() {
  209. return velocidad;
  210. }
  211.  
  212. public void setVelocidad(Integer velocidad) {
  213. this.velocidad = velocidad;
  214. }
  215.  
  216.  
  217. public Float getDiametroPata() {
  218. return diametroPata;
  219. }
  220.  
  221. public void setDiametroPata(Float diametroPata) {
  222. this.diametroPata = diametroPata;
  223. }
  224.  
  225. public Float getEspesorPata() {
  226. return espesorPata;
  227. }
  228.  
  229. public void setEspesorPata(Float espesorPata) {
  230. this.espesorPata = espesorPata;
  231. }
  232.  
  233. public Float getAlturaPata() {
  234. return alturaPata;
  235. }
  236.  
  237. public void setAlturaPata(Float alturaPata) {
  238. this.alturaPata = alturaPata;
  239. }
  240.  
  241.  
  242. public Float getCavidadDiametro() {
  243. return cavidadDiametro;
  244. }
  245.  
  246. public void setCavidadDiametro(Float cavidadDiametro) {
  247. this.cavidadDiametro = cavidadDiametro;
  248. }
  249.  
  250. public Float getCavidadProfundidad() {
  251. return cavidadProfundidad;
  252. }
  253.  
  254. public void setCavidadProfundidad(Float cavidadProfundidad) {
  255. this.cavidadProfundidad = cavidadProfundidad;
  256. }
  257.  
  258.  
  259. @XmlTransient
  260. public Collection<Modelo> getModeloCollection() {
  261. return modeloCollection;
  262. }
  263.  
  264. public void setModeloCollection(Collection<Modelo> modeloCollection) {
  265. this.modeloCollection = modeloCollection;
  266. }
  267.  
  268. @XmlTransient
  269. public Collection<Modelo> getModeloCollection1() {
  270. return modeloCollection1;
  271. }
  272.  
  273. public void setModeloCollection1(Collection<Modelo> modeloCollection1) {
  274. this.modeloCollection1 = modeloCollection1;
  275. }
  276.  
  277. public CategoriaProducto getCategoria() {
  278. return categoria;
  279. }
  280.  
  281. public void setCategoria(CategoriaProducto categoria) {
  282. this.categoria = categoria;
  283. }
  284.  
  285. public Refaccion getAgujas() {
  286. return agujas;
  287. }
  288.  
  289. public void setAgujas(Refaccion agujas) {
  290. this.agujas = agujas;
  291. }
  292.  
  293. public Refaccion getGuia() {
  294. return guia;
  295. }
  296.  
  297. public void setGuia(Refaccion guia) {
  298. this.guia = guia;
  299. }
  300.  
  301. @Override
  302. public int hashCode() {
  303. int hash = 0;
  304. hash += (id != null ? id.hashCode() : 0);
  305. return hash;
  306. }
  307.  
  308. @Override
  309. public boolean equals(Object object) {
  310. // TODO: Warning - this method won't work in the case the id fields are not set
  311. if (!(object instanceof Modelo)) {
  312. return false;
  313. }
  314. Modelo other = (Modelo) object;
  315. if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
  316. return false;
  317. }
  318. return true;
  319. }
  320.  
  321. @Override
  322. public String toString() {
  323. return "Modelo{" + "id=" + id + ", modelo=" + modelo + ", idTamano=" + idTamano + ", espesorPastilla=" + espesorPastilla + ", espesorBoton=" + espesorBoton + ", lineasOMm=" + lineasOMm + ", centroOFrente=" + centroOFrente + ", diametroEspalda=" + diametroEspalda + ", rectificado=" + rectificado + ", velocidad=" + velocidad + ", materialEfecto=" + materialEfecto + ", fotoCelda=" + fotoCelda + ", inclinacion=" + inclinacion + ", diametroPata=" + diametroPata + ", espesorPata=" + espesorPata + ", alturaPata=" + alturaPata + ", observaciones=" + observaciones + ", cavidadDiametro=" + cavidadDiametro + ", cavidadProfundidad=" + cavidadProfundidad + ", figura=" + figura + ", modeloCollection=" + modeloCollection + ", modeloCollection1=" + modeloCollection1 + ", categoria=" + categoria + ", agujas=" + agujas + ", guia=" + guia + '}';
  324. }
  325.  
  326. public String getModelo() {
  327. return modelo;
  328. }
  329.  
  330. public void setModelo(String modelo) {
  331. this.modelo = modelo;
  332. }
  333.  
  334. public String getMaterialEfecto() {
  335. return materialEfecto;
  336. }
  337.  
  338. public void setMaterialEfecto(String materialEfecto) {
  339. this.materialEfecto = materialEfecto;
  340. }
  341.  
  342. public String getFotoCelda() {
  343. return fotoCelda;
  344. }
  345.  
  346. public void setFotoCelda(String fotoCelda) {
  347. this.fotoCelda = fotoCelda;
  348. }
  349.  
  350. public String getInclinacion() {
  351. return inclinacion;
  352. }
  353.  
  354. public void setInclinacion(String inclinacion) {
  355. this.inclinacion = inclinacion;
  356. }
  357.  
  358. public String getObservaciones() {
  359. return observaciones;
  360. }
  361.  
  362. public void setObservaciones(String observaciones) {
  363. this.observaciones = observaciones;
  364. }
  365.  
  366. public String getFigura() {
  367. return figura;
  368. }
  369.  
  370. public void setFigura(String figura) {
  371. this.figura = figura;
  372. }
  373.  
  374.  
  375.  
  376. }
  377.  
  378. @RequestMapping(value="admin/modelo", method = RequestMethod.POST)
  379. public ModelAndView nuevoModelo(
  380. @Valid Modelo modelo
  381. ,BindingResult br
  382. ){
  383. ModelAndView mav = new ModelAndView();
  384. //COMPROBAMOS SI EL MODELO EXISTE
  385. if (modeloService.modeloExist(modelo.getModelo())) {
  386. br.rejectValue("modelo", "error.modelo", "Ya hay un modelo con ese nombre");
  387. }
  388.  
  389. if (br.hasErrors()) {
  390. mav.setViewName("costos/modelo");
  391. }else{
  392. //GRABAMOS EL MODELO
  393. if (modeloService.saveModelo(modelo)) {
  394. mav.addObject("success", "Se registro el modelo con exito.");
  395. mav.addObject("modelo", new Modelo());
  396. } else {
  397. mav.addObject("Error", "Algo paso y no se pudo guardar el modelo");
  398. }
  399. }
  400.  
  401. mav.addObject("modelo", new Modelo());
  402.  
  403. mav.setViewName("costos/modelo");
  404. mav.addAllObjects(gds.costos_modelo(gds.getUser()));
  405. return mav;
  406. }
  407.  
  408. @RequestMapping(value="admin/modelo/modificar/{id}", method = RequestMethod.GET)
  409. public ModelAndView nuevoModelo(
  410. @PathVariable("id") int id){
  411.  
  412. ModelAndView mav = new ModelAndView();
  413.  
  414. if (modeloService.modeloExist(id)) {
  415. mav.addObject("modelo", modeloService.findModeloById(id));
  416. }else{
  417. mav.addObject("error", "El modelo no existe: "+id);
  418. mav.addObject("user", new Modelo());
  419.  
  420. }
  421.  
  422. //RECUERDA QUE EL SUBMIT DEL FORM SE CAMBIA SI EL ID ES 0, OSEA QUE
  423. // NO HAY ID.;
  424. mav.setViewName("costos/modelo");
  425. mav.addAllObjects(gds.costos_modelo(gds.getUser()));
  426. return mav;
  427. }
Add Comment
Please, Sign In to add comment