Checkboxes should be easy right?
theseamnewbie Jul 23, 2008 1:39 AMOk, I'm a total n00b so please forgive me for the following post.
I have an object called Course. In this Course object is a Collection of CourseCurriculum objects.
When on my page to add a new course (or edit for that matter) I would like to have checkoxes so the user can check which curriculums the course belongs too. The values that get checked should be stored in the Collection of CourseCurriculum objects within the new Course object.
The list of curriculums needs to come from the database, so I am using h:selectManyCheckbox which (in theory) is populated with a list of curriculums.
The problem that I'm running into is that I can't even render the page without the following error:
Exception while calling encodeEnd on component : {Component-Path : [Class: org.ajax4jsf.component.AjaxViewRoot,ViewId: /ddlTest.xhtml][Class: javax.faces.component.html.HtmlForm,Id: j_id0][Class: javax.faces.component.html.HtmlSelectManyCheckbox,Id: j_id1]} Caused by: cause
I've tried everything I can think of, but I'm stuck. Right now I have just a simple web page that should display a bunch of checkboxes of courses.
Below is what code I have so far:
Entity:
Course.java <...> @Entity @Name("course") public class Course implements Serializable{ private long courseID; private String courseFullName; private Collection<CourseCurriculum> cCurriculum;
Bean:
CourseListAction.java <...> @Stateful @Name("CourseListSeam") public class CourseListAction implements CourseList, Serializable { @In(required=false) @Out(required=false, scope = ScopeType.SESSION) @DataModelSelection protected Course course; @DataModel private Collection<Course> courses; @PersistenceContext(unitName = "ELCPU") private EntityManager entityManager; @Factory @Observer("courseConfirmed") public Collection<Course> getCourses(){ //get list of all courses courses = entityManager.createQuery("SELECT crs FROM Course crs ORDER BY crs.courseID").getResultList(); //return list return courses; }
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "" title="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">" class="link">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns = "http://www.w3.org/1999/xhtml" xmlns:ui = "http://java.sun.com/jsf/facelets" xmlns:h = "http://java.sun.com/jsf/html" xmlns:f = "http://java.sun.com/jsf/core" xmlns:s = "http://jboss.com/products/seam/taglib" xmlns:a4j = "http://richfaces.org/a4j" xmlns:rich = "http://richfaces.org/rich"> <body> <ui:composition> <h:form> <h:selectManyCheckbox value="#{CourseListSeam.courses}"> <s:selectItems value="#{CourseListSeam.getCourses}" var="crs" label="#{crs.courseID}"/> </h:selectManyCheckbox> </h:form> </ui:composition> </body> </html>
Please help :(