From 9edbf0231a33b7e2da6cd468e42f5f3e4faebe39 Mon Sep 17 00:00:00 2001 From: Nils Gerstner Date: Mon, 21 Aug 2017 16:03:57 +0200 Subject: [PATCH] coursesBean jsf --- .../com/rotanareg/skolan/CoursesBean.java | 137 ++++++++++++++++++ .../skolan/coursePersist/CourseEntity.java | 1 + .../com/rotanareg/skolan/domains/Course.java | 5 +- src/main/webapp/student.xhtml | 6 + 4 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/rotanareg/skolan/CoursesBean.java diff --git a/src/main/java/com/rotanareg/skolan/CoursesBean.java b/src/main/java/com/rotanareg/skolan/CoursesBean.java new file mode 100644 index 0000000..d36d400 --- /dev/null +++ b/src/main/java/com/rotanareg/skolan/CoursesBean.java @@ -0,0 +1,137 @@ +package com.rotanareg.skolan; + +import javax.ejb.EJB; + + import com.rotanareg.skolan.domains.Course; + import com.rotanareg.skolan.coursePersist.*; + + import javax.faces.bean.ManagedBean; + import javax.faces.bean.RequestScoped; +import java.util.List; + +/** + * Created by Solidbeans on 2017-03-20. + */ + +@ManagedBean +@RequestScoped +public class CoursesBean { + private Long id; + private String name; + private String description; + private String courseNr; + @EJB + CourseService courseService; + + + public String addCourse(){ + if (getId()==null) + courseService.addCourse(new Course(name, description, courseNr)); + else + courseService.updateCourse(new Course(getId(),getName(),getDescription(),getCourseNr())); + + setId(null); + setName(""); + setDescription(""); + setCourseNr(""); + return "course"; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getCourseNr() { + return courseNr; + } + + public void setCourseNr(String courseNr) { + this.courseNr = courseNr; + } + + public CourseService getCourses() { + return courseService; + } + + public void setCourseService(CourseService courseService) { + this.courseService = courseService; + } + // public String editPerson(Long id){ +// PersonDomain personDomain = personService.getPerson(id); +// setId(personDomain.getId()); +// setFirstname(personDomain.getFirstName()); +// setLastname(personDomain.getLastName()); +// return "person"; +// } +// public String removePerson(Long id){ +// personService.removePerson(id); +// return "person"; +// } +// public List getCourses(){ +// return courseService.getCourses(); +// } +// public List getPersonsFilter(){ +// if (myFilter==null || myFilter.equals("")) +// return personService.getPersons(); +// else +// return personService.getPersonsFirtsNameContain(myFilter); +// } +// +// public String getSubmitButtonLabel(){ +// if (id==null) +// return "Add"; +// else +// return "Update"; +// } +// public String getFirstname() { +// return firstname; +// } +// +// public void setFirstname(String firstname) { +// this.firstname = firstname; +// } +// +// public String getLastname() { +// return lastname; +// } +// +// public void setLastname(String lastname) { +// this.lastname = lastname; +// } +// +// public Long getId() { +// return id; +// } +// +// public void setId(Long id) { +// this.id = id; +// } +// +// public String getMyFilter() { +// return myFilter; +// } +// +// public void setMyFilter(String myFilter) { +// this.myFilter = myFilter; +// } +} \ No newline at end of file diff --git a/src/main/java/com/rotanareg/skolan/coursePersist/CourseEntity.java b/src/main/java/com/rotanareg/skolan/coursePersist/CourseEntity.java index 0c23c04..7310d37 100644 --- a/src/main/java/com/rotanareg/skolan/coursePersist/CourseEntity.java +++ b/src/main/java/com/rotanareg/skolan/coursePersist/CourseEntity.java @@ -18,6 +18,7 @@ public class CourseEntity { private Long id; private String name; + @Column(length = 10000) private String description; private String courseNr; diff --git a/src/main/java/com/rotanareg/skolan/domains/Course.java b/src/main/java/com/rotanareg/skolan/domains/Course.java index 98ba738..39f993f 100644 --- a/src/main/java/com/rotanareg/skolan/domains/Course.java +++ b/src/main/java/com/rotanareg/skolan/domains/Course.java @@ -3,18 +3,21 @@ package com.rotanareg.skolan.domains; /** * Created by Nils Gerstner on 8/20/17. */ + public class Course { private long id; private String name; private String description; private String courseNr; - public Course(){ + public Course(String name, String description, String courseNr){ this.name = name; this.description = description; this.courseNr = courseNr; } + + public Course(long id, String name, String description, String courseNr){ this.id = id; this.name = name; diff --git a/src/main/webapp/student.xhtml b/src/main/webapp/student.xhtml index 738a159..9533426 100644 --- a/src/main/webapp/student.xhtml +++ b/src/main/webapp/student.xhtml @@ -10,6 +10,12 @@
+ + +

#{myCourse.name}

+ #{myCourse.description} +
+