Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--cat-create.xhtml-->
- <div class="row">
- <div class="col-md-12 d-flex justify-content-center">
- <div class="form-group">
- <h:outputLabel value="Added On" for="catAddedOnInput"/>
- <span id="catAddedOnInput" class="ui-calendar form-control">
- <p:calendar
- id="popup"
- value="#{catCreateBean.catCreateBindingModel.date}"
- required="true"
- requiredMessage="Added On is required!">
- <f:convertDateTime pattern="m/d/yy"/>
- <!--<f:convertDateTime display="both" pattern = "m/d/yy" />-->
- <!--<f:convertDateTime timeZone="CET" display="both" pattern = "m/d/yy" />-->
- </p:calendar>
- </span>
- </div>
- </div>
- </div>
- <!--CatCreateBean.java-->
- @Named
- @RequestScoped
- public class CatCreateBean {
- private CatCreateBindingModel catCreateBindingModel;
- private CatService catService;
- private ModelMapper modelMapper;
- public CatCreateBean() {
- this.catCreateBindingModel = new CatCreateBindingModel();
- }
- @Inject
- public CatCreateBean(CatCreateBindingModel catCreateBindingModel, CatService catService, ModelMapper modelMapper) {
- this();
- this.catService = catService;
- this.modelMapper = modelMapper;
- }
- public CatCreateBindingModel getCatCreateBindingModel() {
- return this.catCreateBindingModel;
- }
- public void setCatCreateBindingModel(CatCreateBindingModel catCreateBindingModel) {
- this.catCreateBindingModel = catCreateBindingModel;
- }
- public void createCat() throws IOException {
- CatServiceModel catServiceModel = this.modelMapper.map(this.catCreateBindingModel, CatServiceModel.class);
- this.catService.save(catServiceModel);
- ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
- context.redirect("/jsf/all-cats.xhtml");
- }
- }
- <!--CatCreateBindingModel.java-->
- import javax.faces.convert.DateTimeConverter;
- import javax.validation.constraints.*;
- import java.math.BigDecimal;
- import java.time.LocalDate;
- import java.util.Date;
- public class CatCreateBindingModel {
- private String name;
- private String breed;
- private String color;
- private Integer age;
- private String gender;
- private BigDecimal price;
- private Date date;
- private Boolean hasPassport;
- public CatCreateBindingModel() {
- }
- @NotNull
- @Size(min = 2, max = 10)
- public String getName() {
- return this.name;
- }
- public void setName(String name) {
- this.name = name;
- }
- @NotNull
- @Size(min = 5, max = 20)
- public String getBreed() {
- return this.breed;
- }
- public void setBreed(String breed) {
- this.breed = breed;
- }
- @NotNull
- public String getColor() {
- return this.color;
- }
- public void setColor(String color) {
- this.color = color;
- }
- @NotNull
- @Min(1)
- @Max(31)
- public Integer getAge() {
- return this.age;
- }
- public void setAge(Integer age) {
- this.age = age;
- }
- @NotNull
- public String getGender() {
- return this.gender;
- }
- public void setGender(String gender) {
- this.gender = gender;
- }
- @NotNull
- @DecimalMin(value = "0.01")
- public BigDecimal getPrice() {
- return this.price;
- }
- public void setPrice(BigDecimal price) {
- this.price = price;
- }
- @NotNull
- public Date getDate() {
- return this.date;
- }
- public void setDate(Date date) {
- this.date = date;
- }
- @NotNull
- public Boolean getHasPassport() {
- return this.hasPassport;
- }
- public void setHasPassport(Boolean hasPassport) {
- this.hasPassport = hasPassport;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement