Advertisement
valchak

jsf cat-create

Feb 18th, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1.  
  2. <!--cat-create.xhtml-->
  3. <div class="row">
  4. <div class="col-md-12 d-flex justify-content-center">
  5. <div class="form-group">
  6. <h:outputLabel value="Added On" for="catAddedOnInput"/>
  7. <span id="catAddedOnInput" class="ui-calendar form-control">
  8. <p:calendar
  9. id="popup"
  10. value="#{catCreateBean.catCreateBindingModel.date}"
  11. required="true"
  12. requiredMessage="Added On is required!">
  13. <f:convertDateTime pattern="m/d/yy"/>
  14. <!--<f:convertDateTime display="both" pattern = "m/d/yy" />-->
  15. <!--<f:convertDateTime timeZone="CET" display="both" pattern = "m/d/yy" />-->
  16. </p:calendar>
  17. </span>
  18. </div>
  19. </div>
  20. </div>
  21.  
  22.  
  23. <!--CatCreateBean.java-->
  24. @Named
  25. @RequestScoped
  26. public class CatCreateBean {
  27. private CatCreateBindingModel catCreateBindingModel;
  28. private CatService catService;
  29. private ModelMapper modelMapper;
  30.  
  31. public CatCreateBean() {
  32. this.catCreateBindingModel = new CatCreateBindingModel();
  33. }
  34.  
  35. @Inject
  36. public CatCreateBean(CatCreateBindingModel catCreateBindingModel, CatService catService, ModelMapper modelMapper) {
  37. this();
  38. this.catService = catService;
  39. this.modelMapper = modelMapper;
  40.  
  41. }
  42.  
  43. public CatCreateBindingModel getCatCreateBindingModel() {
  44. return this.catCreateBindingModel;
  45. }
  46.  
  47. public void setCatCreateBindingModel(CatCreateBindingModel catCreateBindingModel) {
  48. this.catCreateBindingModel = catCreateBindingModel;
  49. }
  50.  
  51.  
  52. public void createCat() throws IOException {
  53. CatServiceModel catServiceModel = this.modelMapper.map(this.catCreateBindingModel, CatServiceModel.class);
  54.  
  55. this.catService.save(catServiceModel);
  56.  
  57. ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
  58. context.redirect("/jsf/all-cats.xhtml");
  59. }
  60. }
  61.  
  62.  
  63. <!--CatCreateBindingModel.java-->
  64.  
  65. import javax.faces.convert.DateTimeConverter;
  66. import javax.validation.constraints.*;
  67. import java.math.BigDecimal;
  68. import java.time.LocalDate;
  69. import java.util.Date;
  70.  
  71. public class CatCreateBindingModel {
  72. private String name;
  73. private String breed;
  74. private String color;
  75. private Integer age;
  76. private String gender;
  77. private BigDecimal price;
  78. private Date date;
  79. private Boolean hasPassport;
  80.  
  81. public CatCreateBindingModel() {
  82. }
  83.  
  84. @NotNull
  85. @Size(min = 2, max = 10)
  86. public String getName() {
  87. return this.name;
  88. }
  89.  
  90. public void setName(String name) {
  91. this.name = name;
  92. }
  93.  
  94. @NotNull
  95. @Size(min = 5, max = 20)
  96. public String getBreed() {
  97. return this.breed;
  98. }
  99.  
  100. public void setBreed(String breed) {
  101. this.breed = breed;
  102. }
  103.  
  104. @NotNull
  105. public String getColor() {
  106. return this.color;
  107. }
  108.  
  109. public void setColor(String color) {
  110. this.color = color;
  111. }
  112.  
  113. @NotNull
  114. @Min(1)
  115. @Max(31)
  116. public Integer getAge() {
  117. return this.age;
  118. }
  119.  
  120. public void setAge(Integer age) {
  121. this.age = age;
  122. }
  123.  
  124. @NotNull
  125. public String getGender() {
  126. return this.gender;
  127. }
  128.  
  129. public void setGender(String gender) {
  130. this.gender = gender;
  131. }
  132.  
  133. @NotNull
  134. @DecimalMin(value = "0.01")
  135. public BigDecimal getPrice() {
  136. return this.price;
  137. }
  138.  
  139. public void setPrice(BigDecimal price) {
  140. this.price = price;
  141. }
  142.  
  143. @NotNull
  144. public Date getDate() {
  145. return this.date;
  146. }
  147.  
  148. public void setDate(Date date) {
  149. this.date = date;
  150. }
  151.  
  152. @NotNull
  153. public Boolean getHasPassport() {
  154. return this.hasPassport;
  155. }
  156.  
  157. public void setHasPassport(Boolean hasPassport) {
  158. this.hasPassport = hasPassport;
  159. }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement