coursesBean jsf

PlaygroundDevelopment
Nils Gerstner 7 years ago
parent ad6d3083de
commit 9edbf0231a

@ -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<Course> getCourses(){
// return courseService.getCourses();
// }
// public List<PersonDomain> 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;
// }
}

@ -18,6 +18,7 @@ public class CourseEntity {
private Long id;
private String name;
@Column(length = 10000)
private String description;
private String courseNr;

@ -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;

@ -10,6 +10,12 @@
<section>
<h:dataTable value="#{coursesBean.courses.courses}" var="myCourse">
<h:column>
<h1>#{myCourse.name}</h1>
#{myCourse.description}
</h:column>
</h:dataTable>
<h:form>
<h:dataTable value="#{student.lines}" var="line"
styleClass="student-table"

Loading…
Cancel
Save