Advertisement
valchak

jsf calendar

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