Return-Path: Delivered-To: apmail-incubator-click-commits-archive@minotaur.apache.org Received: (qmail 6151 invoked from network); 27 Apr 2009 18:44:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 27 Apr 2009 18:44:01 -0000 Received: (qmail 61835 invoked by uid 500); 27 Apr 2009 18:44:01 -0000 Delivered-To: apmail-incubator-click-commits-archive@incubator.apache.org Received: (qmail 61822 invoked by uid 500); 27 Apr 2009 18:44:01 -0000 Mailing-List: contact click-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: click-dev@incubator.apache.org Delivered-To: mailing list click-commits@incubator.apache.org Received: (qmail 61812 invoked by uid 99); 27 Apr 2009 18:44:01 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Apr 2009 18:44:01 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Apr 2009 18:43:57 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3E326238895F; Mon, 27 Apr 2009 18:43:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r769101 - in /incubator/click/trunk/click/examples: src/ src/org/apache/click/examples/domain/ src/org/apache/click/examples/domain/auto/ src/org/apache/click/examples/page/cayenne/ src/org/apache/click/examples/service/ src/org/apache/clic... Date: Mon, 27 Apr 2009 18:43:35 -0000 To: click-commits@incubator.apache.org From: sabob@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090427184336.3E326238895F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sabob Date: Mon Apr 27 18:43:34 2009 New Revision: 769101 URL: http://svn.apache.org/viewvc?rev=769101&view=rev Log: added two new Cayenne demos (one-to-many and many-to-many) Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/Course.java incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/Student.java incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/StudentHouse.java incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_Course.java incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_Student.java incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_StudentHouse.java incubator/click/trunk/click/examples/src/org/apache/click/examples/page/cayenne/AccommodationDemo.java incubator/click/trunk/click/examples/src/org/apache/click/examples/page/cayenne/EnrollmentDemo.java incubator/click/trunk/click/examples/src/org/apache/click/examples/service/StudentService.java incubator/click/trunk/click/examples/src/org/apache/click/examples/util/courses.txt incubator/click/trunk/click/examples/src/org/apache/click/examples/util/student-houses.txt incubator/click/trunk/click/examples/webapp/cayenne/accommodation-demo.htm incubator/click/trunk/click/examples/webapp/cayenne/enrollment-demo.htm Modified: incubator/click/trunk/click/examples/src/cayenneMap.map.xml incubator/click/trunk/click/examples/src/org/apache/click/examples/util/DatabaseInitFilter.java incubator/click/trunk/click/examples/webapp/WEB-INF/menu.xml Modified: incubator/click/trunk/click/examples/src/cayenneMap.map.xml URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/cayenneMap.map.xml?rev=769101&r1=769100&r2=769101&view=diff ============================================================================== --- incubator/click/trunk/click/examples/src/cayenneMap.map.xml (original) +++ incubator/click/trunk/click/examples/src/cayenneMap.map.xml Mon Apr 27 18:43:34 2009 @@ -20,6 +20,10 @@ + + + + @@ -38,12 +42,25 @@ + + + + + + + + + + + + + @@ -73,6 +90,9 @@ + + + @@ -94,6 +114,12 @@ + + + + + + @@ -112,8 +138,30 @@ + + + + + + + + + + + + + + + + + + + + + + Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/Course.java URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/Course.java?rev=769101&view=auto ============================================================================== --- incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/Course.java (added) +++ incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/Course.java Mon Apr 27 18:43:34 2009 @@ -0,0 +1,10 @@ +package org.apache.click.examples.domain; + +import org.apache.click.examples.domain.auto._Course; + +public class Course extends _Course { + +} + + + Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/Student.java URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/Student.java?rev=769101&view=auto ============================================================================== --- incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/Student.java (added) +++ incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/Student.java Mon Apr 27 18:43:34 2009 @@ -0,0 +1,10 @@ +package org.apache.click.examples.domain; + +import org.apache.click.examples.domain.auto._Student; + +public class Student extends _Student { + +} + + + Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/StudentHouse.java URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/StudentHouse.java?rev=769101&view=auto ============================================================================== --- incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/StudentHouse.java (added) +++ incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/StudentHouse.java Mon Apr 27 18:43:34 2009 @@ -0,0 +1,10 @@ +package org.apache.click.examples.domain; + +import org.apache.click.examples.domain.auto._StudentHouse; + +public class StudentHouse extends _StudentHouse { + +} + + + Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_Course.java URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_Course.java?rev=769101&view=auto ============================================================================== --- incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_Course.java (added) +++ incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_Course.java Mon Apr 27 18:43:34 2009 @@ -0,0 +1,36 @@ +package org.apache.click.examples.domain.auto; + +import java.util.List; + +/** Class _Course was generated by Cayenne. + * It is probably a good idea to avoid changing this class manually, + * since it may be overwritten next time code is regenerated. + * If you need to make any customizations, please use subclass. + */ +public class _Course extends org.apache.click.examples.domain.BaseEntity { + + public static final String NAME_PROPERTY = "name"; + public static final String STUDENTS_PROPERTY = "students"; + + public static final String ID_PK_COLUMN = "id"; + + public void setName(String name) { + writeProperty("name", name); + } + public String getName() { + return (String)readProperty("name"); + } + + + public void addToStudents(org.apache.click.examples.domain.Student obj) { + addToManyTarget("students", obj, true); + } + public void removeFromStudents(org.apache.click.examples.domain.Student obj) { + removeToManyTarget("students", obj, true); + } + public List getStudents() { + return (List)readProperty("students"); + } + + +} Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_Student.java URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_Student.java?rev=769101&view=auto ============================================================================== --- incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_Student.java (added) +++ incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_Student.java Mon Apr 27 18:43:34 2009 @@ -0,0 +1,46 @@ +package org.apache.click.examples.domain.auto; + +import java.util.List; + +/** Class _Student was generated by Cayenne. + * It is probably a good idea to avoid changing this class manually, + * since it may be overwritten next time code is regenerated. + * If you need to make any customizations, please use subclass. + */ +public class _Student extends org.apache.click.examples.domain.BaseEntity { + + public static final String NAME_PROPERTY = "name"; + public static final String COURSES_PROPERTY = "courses"; + public static final String STUDENT_HOUSE_PROPERTY = "studentHouse"; + + public static final String ID_PK_COLUMN = "id"; + + public void setName(String name) { + writeProperty("name", name); + } + public String getName() { + return (String)readProperty("name"); + } + + + public void addToCourses(org.apache.click.examples.domain.Course obj) { + addToManyTarget("courses", obj, true); + } + public void removeFromCourses(org.apache.click.examples.domain.Course obj) { + removeToManyTarget("courses", obj, true); + } + public List getCourses() { + return (List)readProperty("courses"); + } + + + public void setStudentHouse(org.apache.click.examples.domain.StudentHouse studentHouse) { + setToOneTarget("studentHouse", studentHouse, true); + } + + public org.apache.click.examples.domain.StudentHouse getStudentHouse() { + return (org.apache.click.examples.domain.StudentHouse)readProperty("studentHouse"); + } + + +} Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_StudentHouse.java URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_StudentHouse.java?rev=769101&view=auto ============================================================================== --- incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_StudentHouse.java (added) +++ incubator/click/trunk/click/examples/src/org/apache/click/examples/domain/auto/_StudentHouse.java Mon Apr 27 18:43:34 2009 @@ -0,0 +1,36 @@ +package org.apache.click.examples.domain.auto; + +import java.util.List; + +/** Class _StudentHouse was generated by Cayenne. + * It is probably a good idea to avoid changing this class manually, + * since it may be overwritten next time code is regenerated. + * If you need to make any customizations, please use subclass. + */ +public class _StudentHouse extends org.apache.click.examples.domain.BaseEntity { + + public static final String NAME_PROPERTY = "name"; + public static final String STUDENT_PROPERTY = "student"; + + public static final String ID_PK_COLUMN = "id"; + + public void setName(String name) { + writeProperty("name", name); + } + public String getName() { + return (String)readProperty("name"); + } + + + public void addToStudent(org.apache.click.examples.domain.Student obj) { + addToManyTarget("student", obj, true); + } + public void removeFromStudent(org.apache.click.examples.domain.Student obj) { + removeToManyTarget("student", obj, true); + } + public List getStudent() { + return (List)readProperty("student"); + } + + +} Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/page/cayenne/AccommodationDemo.java URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/page/cayenne/AccommodationDemo.java?rev=769101&view=auto ============================================================================== --- incubator/click/trunk/click/examples/src/org/apache/click/examples/page/cayenne/AccommodationDemo.java (added) +++ incubator/click/trunk/click/examples/src/org/apache/click/examples/page/cayenne/AccommodationDemo.java Mon Apr 27 18:43:34 2009 @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.click.examples.page.cayenne; + +import java.util.List; +import javax.annotation.Resource; +import org.apache.cayenne.DataObject; + +import org.apache.cayenne.query.SelectQuery; +import org.apache.click.Context; +import org.apache.click.control.Column; +import org.apache.click.control.Decorator; +import org.apache.click.control.TextField; +import org.apache.click.examples.domain.Student; +import org.apache.click.examples.domain.StudentHouse; +import org.apache.click.examples.service.StudentService; +import org.apache.click.extras.cayenne.PropertySelect; +import org.springframework.stereotype.Component; + +/** + * This example demonstrates how to represent a one-to-many relationship + * between StudentHouse and Students using Apache Click. + * + * A Student House can have many Students, and a Student can only live + * in one Student House. + * + * The relationship is managed by a Select control. + * + * @author Bob Schellink + */ +@Component +public class AccommodationDemo extends FormTablePage { + + @Resource(name="studentService") + private StudentService studentService; + + private PropertySelect select; + + /** + * @see FormTablePage#onInit() + */ + public void onInit() { + form.add(new TextField("name")).setRequired(true); + + select = new PropertySelect("studentHouse"); + + // Populate the Select control with Student Houses where "id" is the + // option value and "name" is the option label + select.setSelectQuery(new SelectQuery(StudentHouse.class)); + select.setOptionLabel("name"); + select.setOptional(true); + form.add(select); + + // Table + table.addColumn(new Column("id")); + table.addColumn(new Column("name")); + table.addColumn(new Column("studentHouse")).setDecorator(new Decorator() { + + public String render(Object object, Context context) { + Student student = (Student) object; + if (student.getStudentHouse() != null) { + return student.getStudentHouse().getName(); + } else { + return ""; + } + } + }); + + super.onInit(); + } + + /** + * @see FormTablePage#getDataObject(Object) + */ + public DataObject getDataObject(Object id) { + return studentService.getStudent(id); + } + + /** + * @see FormTablePage#getDataObjectClass() + */ + public Class getDataObjectClass() { + return Student.class; + } + + /** + * @see FormTablePage#getRowList() + */ + public List getRowList() { + return studentService.getStudentsByHouse(); + } +} Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/page/cayenne/EnrollmentDemo.java URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/page/cayenne/EnrollmentDemo.java?rev=769101&view=auto ============================================================================== --- incubator/click/trunk/click/examples/src/org/apache/click/examples/page/cayenne/EnrollmentDemo.java (added) +++ incubator/click/trunk/click/examples/src/org/apache/click/examples/page/cayenne/EnrollmentDemo.java Mon Apr 27 18:43:34 2009 @@ -0,0 +1,150 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.click.examples.page.cayenne; + +import java.util.List; +import javax.annotation.Resource; +import org.apache.cayenne.DataObject; + +import org.apache.click.control.Column; +import org.apache.click.control.TextField; +import org.apache.click.examples.domain.Course; +import org.apache.click.examples.domain.Student; +import org.apache.click.examples.service.StudentService; +import org.apache.click.extras.control.PickList; +import org.springframework.stereotype.Component; + +/** + * This example demonstrates how to represent a many-to-many relationship + * between Students and Courses using Apache Click. + * + * A Student can take many Courses, and a Course can be taken by many Students. + * + * The relationship is managed by a PickList control. + * + * @author Bob Schellink + */ +@Component +public class EnrollmentDemo extends FormTablePage { + + @Resource(name="studentService") + private StudentService studentService; + + private PickList pickList; + + /** + * @see FormTablePage#onInit() + */ + public void onInit() { + form.add(new TextField("name")).setRequired(true); + + pickList = new PickList("courseList", "Courses"); + pickList.addAll(studentService.getCourses(), "id", "name"); + form.add(pickList); + + // Table + table.addColumn(new Column("id")); + table.addColumn(new Column("name")); + + super.onInit(); + } + + /** + * @see FormTablePage#onSaveClick() + */ + public boolean onSaveClick() { + if (form.isValid()) { + Student student = (Student) form.getDataObject(); + + List courseIds = pickList.getSelectedValues(); + studentService.setStudentCourses(student, courseIds); + + saveDataObject(student); + + clear(); + } + return true; + } + + /** + * @see FormTablePage#onEditClick() + */ + public boolean onEditClick() { + Student student = getSelectedStudent(); + + // If no student is selected, exist early + if (student == null) { + return true; + } + + // Add each student course to the PickList + List courses = student.getCourses(); + for (int i = 0; i < courses.size(); i++) { + Course course = (Course) courses.get(i); + pickList.addSelectedValue(course.getId().toString()); + } + form.setDataObject(student); + + return true; + } + + /** + * @see FormTablePage#clear() + */ + public void clear() { + pickList.setSelectedValues(null); + super.clear(); + } + + /** + * @see FormTablePage#getDataObject(Object) + */ + public DataObject getDataObject(Object id) { + return studentService.getStudent(id); + } + + /** + * @see FormTablePage#getDataObjectClass() + */ + public Class getDataObjectClass() { + return Student.class; + } + + /** + * @see FormTablePage#getRowList() + */ + public List getRowList() { + return studentService.getStudents(); + } + + /** + * Return the selected student or null if no student is selected. + * + * @return the selected student or null if no student is selected + */ + private Student getSelectedStudent() { + Student student = null; + + Integer id = editLink.getValueInteger(); + if (id != null) { + student = (Student) getDataObject(id); + } + return student; + } +} Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/service/StudentService.java URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/service/StudentService.java?rev=769101&view=auto ============================================================================== --- incubator/click/trunk/click/examples/src/org/apache/click/examples/service/StudentService.java (added) +++ incubator/click/trunk/click/examples/src/org/apache/click/examples/service/StudentService.java Mon Apr 27 18:43:34 2009 @@ -0,0 +1,149 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.click.examples.service; + +import java.util.Iterator; +import java.util.List; +import org.apache.cayenne.exp.ExpressionFactory; +import org.apache.cayenne.query.Ordering; +import org.apache.cayenne.query.SelectQuery; +import org.apache.click.examples.domain.Course; +import org.apache.click.examples.domain.Student; +import org.apache.click.examples.domain.StudentHouse; +import org.apache.click.extras.cayenne.CayenneTemplate; +import org.springframework.stereotype.Component; + +/** + * Provides a Student Service. + * + * @author Bob Schellink + */ +@Component +public class StudentService extends CayenneTemplate { + + // ---------------------------------------------------------- Student logic + + public List getStudents() { + SelectQuery query = new SelectQuery(Student.class); + query.addPrefetch("studentHouse"); + query.addOrdering("db:id", true); + return performQuery(query); + } + + public Student getStudent(Object id) { + SelectQuery query = new SelectQuery(Student.class); + query.addPrefetch("courses"); + query.addPrefetch("studentHouse"); + query.setQualifier(ExpressionFactory.matchDbExp("id", id)); + + List students = getDataContext().performQuery(query); + + if (students.size() == 0) { + return null; + } + + if (students.size() == 1) { + return (Student) students.get(0); + } else { + String msg = "SelectQuery for " + Student.class.getName() + + " where id equals " + id + " returned " + + students.size() + " rows"; + throw new RuntimeException(msg); + } + } + + public void saveStudent(Student student) { + if (student.getObjectContext() == null) { + registerNewObject(student); + } + commitChanges(); + } + + // ----------------------------------------------------------- Course logic + + public void setStudentCourses(Student student, List courseIds) { + // First remove current courses + List removes = student.getCourses(); + for (int i = removes.size() - 1; i >= 0; i--) { + Course course = (Course) removes.get(i); + student.removeFromCourses(course); + } + + if (courseIds == null || courseIds.isEmpty()) { + return; + } + + // Next, set the new courses + SelectQuery query = new SelectQuery(Course.class); + query.setQualifier(ExpressionFactory.inDbExp("id", courseIds)); + List courses = getDataContext().performQuery(query); + + for (Iterator it = courses.iterator(); it.hasNext(); ) { + Course course = (Course) it.next() ; + student.addToCourses(course); + } + } + + public List getCourses() { + SelectQuery query = new SelectQuery(Course.class); + query.addOrdering("db:id", true); + return performQuery(query); + } + + public Course getCourse(Object id) { + return (Course) getObjectForPK(Course.class, id); + } + + public void saveCourse(Course course) { + if (course.getObjectContext() == null) { + registerNewObject(course); + } + commitChanges(); + } + + // ---------------------------------------------------- Student House logic + + public List getStudentsByHouse() { + SelectQuery query = new SelectQuery(Student.class); + query.addPrefetch("studentHouse"); + + // Add in-memory ordering + Ordering ordering = new Ordering("studentHouse.name", true); + List result = performQuery(query); + ordering.orderList(result); + return result; + } + + public List getStudentHouses() { + SelectQuery query = new SelectQuery(StudentHouse.class); + query.addOrdering(StudentHouse.NAME_PROPERTY, true); + return performQuery(query); + } + + public StudentHouse getStudentHouse(Object id) { + return (StudentHouse) getObjectForPK(StudentHouse.class, id); + } + + public void saveStudentHouse(StudentHouse studentHouse) { + if (studentHouse.getObjectContext() == null) { + registerNewObject(studentHouse); + } + commitChanges(); + } +} Modified: incubator/click/trunk/click/examples/src/org/apache/click/examples/util/DatabaseInitFilter.java URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/util/DatabaseInitFilter.java?rev=769101&r1=769100&r2=769101&view=diff ============================================================================== --- incubator/click/trunk/click/examples/src/org/apache/click/examples/util/DatabaseInitFilter.java (original) +++ incubator/click/trunk/click/examples/src/org/apache/click/examples/util/DatabaseInitFilter.java Mon Apr 27 18:43:34 2009 @@ -51,6 +51,8 @@ import org.apache.cayenne.conf.ServletUtil; import org.apache.cayenne.map.DataMap; import org.apache.cayenne.query.SelectQuery; +import org.apache.click.examples.domain.Course; +import org.apache.click.examples.domain.StudentHouse; import org.apache.commons.lang.WordUtils; /** @@ -158,6 +160,12 @@ // Load post codes data file loadPostCodes(dataContext); + // Load course data file + loadCourses(dataContext); + + // Load student houses data file + loadStudentHouses(dataContext); + dataContext.commitChanges(); } @@ -275,6 +283,34 @@ }); } + private void loadCourses(final DataContext dataContext) throws IOException { + loadFile("courses.txt", dataContext, new LineProcessor() { + public void processLine(String line, DataContext context) { + StringTokenizer tokenizer = new StringTokenizer(line, ","); + + Course course = new Course(); + + course.setName(next(tokenizer)); + + context.registerNewObject(course); + } + }); + } + + private void loadStudentHouses(final DataContext dataContext) throws IOException { + loadFile("student-houses.txt", dataContext, new LineProcessor() { + public void processLine(String line, DataContext context) { + StringTokenizer tokenizer = new StringTokenizer(line, ","); + + StudentHouse studentHouse = new StudentHouse(); + + studentHouse.setName(next(tokenizer)); + + context.registerNewObject(studentHouse); + } + }); + } + private static interface LineProcessor { public void processLine(String line, DataContext dataContext); } Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/util/courses.txt URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/util/courses.txt?rev=769101&view=auto ============================================================================== --- incubator/click/trunk/click/examples/src/org/apache/click/examples/util/courses.txt (added) +++ incubator/click/trunk/click/examples/src/org/apache/click/examples/util/courses.txt Mon Apr 27 18:43:34 2009 @@ -0,0 +1,27 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# +# COURSE table data file, format: +# name +# +Applied Mathematics +Applied Physics +Bioengineering +Computer Science +Electrical Engineering +Mechanical Engineering \ No newline at end of file Added: incubator/click/trunk/click/examples/src/org/apache/click/examples/util/student-houses.txt URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/util/student-houses.txt?rev=769101&view=auto ============================================================================== --- incubator/click/trunk/click/examples/src/org/apache/click/examples/util/student-houses.txt (added) +++ incubator/click/trunk/click/examples/src/org/apache/click/examples/util/student-houses.txt Mon Apr 27 18:43:34 2009 @@ -0,0 +1,26 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# +# STUDENT_HOUSE table data file, format: +# name +# + +House Vernius +House Ordos +House Corrino +House Boro \ No newline at end of file Modified: incubator/click/trunk/click/examples/webapp/WEB-INF/menu.xml URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/webapp/WEB-INF/menu.xml?rev=769101&r1=769100&r2=769101&view=diff ============================================================================== --- incubator/click/trunk/click/examples/webapp/WEB-INF/menu.xml (original) +++ incubator/click/trunk/click/examples/webapp/WEB-INF/menu.xml Mon Apr 27 18:43:34 2009 @@ -139,6 +139,8 @@ + + Added: incubator/click/trunk/click/examples/webapp/cayenne/accommodation-demo.htm URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/webapp/cayenne/accommodation-demo.htm?rev=769101&view=auto ============================================================================== --- incubator/click/trunk/click/examples/webapp/cayenne/accommodation-demo.htm (added) +++ incubator/click/trunk/click/examples/webapp/cayenne/accommodation-demo.htm Mon Apr 27 18:43:34 2009 @@ -0,0 +1,32 @@ + + +This example demonstrates a one-to-many relationship between a student +and a student house. A student stays in one student house, but a student house +has many students. + +

+ +#if ($error) $error #end + +$form + +

+ +$table \ No newline at end of file Added: incubator/click/trunk/click/examples/webapp/cayenne/enrollment-demo.htm URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/webapp/cayenne/enrollment-demo.htm?rev=769101&view=auto ============================================================================== --- incubator/click/trunk/click/examples/webapp/cayenne/enrollment-demo.htm (added) +++ incubator/click/trunk/click/examples/webapp/cayenne/enrollment-demo.htm Mon Apr 27 18:43:34 2009 @@ -0,0 +1,24 @@ + + +$form + +

+ +$table \ No newline at end of file