You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by jk...@apache.org on 2006/02/11 23:57:48 UTC
svn commit: r377078 - in /jakarta/tapestry/trunk: ./ config/
examples/TimeTracker/src/config/ examples/TimeTracker/src/context/
examples/TimeTracker/src/context/WEB-INF/
examples/TimeTracker/src/java/org/apache/tapestry/timetracker/dao/
examples/TimeTr...
Author: jkuhnert
Date: Sat Feb 11 14:57:45 2006
New Revision: 377078
URL: http://svn.apache.org/viewcvs?rev=377078&view=rev
Log:
Added a new property selection model class, more timetracker demo work
Added:
jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/Home.page
jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/timetracker.dao.xml
jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/dao/
jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/dao/BaseDao.java
jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/dao/ProjectDao.java
jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/model/
jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/model/Project.java
jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/
jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/TaskEntryPage.java
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/form/BeanPropertySelectionModel.java
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/form/BeanPropertySelectionModelTest.java
jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/form/SimpleBean.java
Modified:
jakarta/tapestry/trunk/.classpath
jakarta/tapestry/trunk/config/common.properties
jakarta/tapestry/trunk/examples/TimeTracker/src/config/createDatabase.sql
jakarta/tapestry/trunk/examples/TimeTracker/src/context/Home.html
jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/Home.properties
jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/hivemodule.xml
jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/timetracker.db.xml
jakarta/tapestry/trunk/framework/build.xml
jakarta/tapestry/trunk/status.xml
Modified: jakarta/tapestry/trunk/.classpath
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/.classpath?rev=377078&r1=377077&r2=377078&view=diff
==============================================================================
Binary files - no diff available.
Modified: jakarta/tapestry/trunk/config/common.properties
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/config/common.properties?rev=377078&r1=377077&r2=377078&view=diff
==============================================================================
--- jakarta/tapestry/trunk/config/common.properties (original)
+++ jakarta/tapestry/trunk/config/common.properties Sat Feb 11 14:57:45 2006
@@ -21,6 +21,7 @@
dbcp.version=1.2
pool.version=1.2
collections.version=3.1
+beanutils.version=1.7.0
oro.version=2.0.8
servlet.version=2.3
log4j.version=1.2.8
Modified: jakarta/tapestry/trunk/examples/TimeTracker/src/config/createDatabase.sql
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/TimeTracker/src/config/createDatabase.sql?rev=377078&r1=377077&r2=377078&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/TimeTracker/src/config/createDatabase.sql (original)
+++ jakarta/tapestry/trunk/examples/TimeTracker/src/config/createDatabase.sql Sat Feb 11 14:57:45 2006
@@ -1,8 +1,25 @@
create table projects (
project_id integer not null generated always as identity(start with 100, increment by 1),
- name varchar(40) not null,
+ name varchar(40) not null
);
+alter table projects add constraint projects_pk
+primary key(project_id);
+
+alter table projects add constraint name_unique
+unique (name);
+
insert into projects(name) values ('Code Zeitgeist');
insert into projects(name) values ('Zooland Systems');
-insert into projects(name) values ('Weedasher Industries');
\ No newline at end of file
+insert into projects(name) values ('Weedasher Industries');
+
+create table tasks (
+ task_id integer not null generated always as identity(start with 100, increment by 1),
+ project_id integer not null,
+ start_dt timestamp not null,
+ end_dt timestamp not null,
+ descr_txt varchar(200) not null
+);
+
+alter table tasks add constraint tasks_fk
+Foreign Key(project_id) references projects (project_id);
Modified: jakarta/tapestry/trunk/examples/TimeTracker/src/context/Home.html
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/TimeTracker/src/context/Home.html?rev=377078&r1=377077&r2=377078&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/TimeTracker/src/context/Home.html (original)
+++ jakarta/tapestry/trunk/examples/TimeTracker/src/context/Home.html Sat Feb 11 14:57:45 2006
@@ -4,17 +4,15 @@
core features available in tapestry, as well as how a sample application might be built
using them.
-<form >
+<form jwcid="@Form" >
<fieldset>
<legend><span jwcid="@Insert" value="message:new.task"/></legend>
+
<div class="fm-hopt">
- <label for="fm-state">Project</label>
- <select id="fm-state" name="fm-state">
- <option value="" selected="selected">Select..</option>
- <option value="UNK">Tapestry</option>
- <option value="AL">Code zigest</option>
- </select>
+ <span jwcid="@FieldLabel" field="component:projectChoose" />
+ <span jwcid="projectChoose" />
</div>
+
<div class="fm-hreq">
<label for="fm-firstname">Start</label>
<input style="width:auto" size="10" name="fm-firstname" id="fm-firstname" type="text" />
Added: jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/Home.page
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/Home.page?rev=377078&view=auto
==============================================================================
--- jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/Home.page (added)
+++ jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/Home.page Sat Feb 11 14:57:45 2006
@@ -0,0 +1,51 @@
+<?xml version="1.0"?>
+<!--
+ Copyright 2004, 2005 The Apache Software Foundation
+
+ Licensed 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.
+-->
+
+<!DOCTYPE page-specification PUBLIC
+ "-//Apache Software Foundation//Tapestry Specification 4.0//EN"
+ "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">
+
+<page-specification class="org.apache.tapestry.timetracker.page.TaskEntryPage">
+
+ <!--
+ <bean name="delegate" class="org.apache.tapestry.workbench.WorkbenchValidationDelegate" property="delegate"/>
+
+ <property name="clientValidationEnabled" persist="client" initial-value="true"/>
+ <property name="includeWeek" persist="client"/>
+ <property name="startDate" persist="client"/>
+ <property name="endDate" persist="client"/>
+
+ <bean name="required" class="org.apache.tapestry.form.validator.Required"></bean>
+ <bean name="maxDate" class="org.apache.tapestry.form.validator.MaxDate">
+ <set name="maxDate" value="new java.util.Date()"></set>
+ </bean>
+ <bean name="minDate" class="org.apache.tapestry.form.validator.MinDate">
+ <set name="minDate" value="new java.util.Date()"></set>
+ </bean>
+
+ <component id="inputEnabled" type="Checkbox">
+ <binding name="value" value="clientValidationEnabled"/>
+ <binding name="onchange" value="literal:javascript:this.form.events.submit();"/>
+ </component>
+
+ <component id="showError" type="ShowError">
+ <binding name="delegate" value="bean:delegate"/>
+ </component>
+ -->
+
+</page-specification>
+
Modified: jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/Home.properties
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/Home.properties?rev=377078&r1=377077&r2=377078&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/Home.properties (original)
+++ jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/Home.properties Sat Feb 11 14:57:45 2006
@@ -1 +1,3 @@
-new.task=Task Entry
\ No newline at end of file
+new.task=Task Entry
+
+choose.project=Project
\ No newline at end of file
Modified: jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/hivemodule.xml
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/hivemodule.xml?rev=377078&r1=377077&r2=377078&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/hivemodule.xml (original)
+++ jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/hivemodule.xml Sat Feb 11 14:57:45 2006
@@ -22,4 +22,5 @@
</contribution>
<sub-module descriptor="timetracker.db.xml" />
+ <sub-module descriptor="timetracker.dao.xml" />
</module>
Added: jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/timetracker.dao.xml
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/timetracker.dao.xml?rev=377078&view=auto
==============================================================================
--- jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/timetracker.dao.xml (added)
+++ jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/timetracker.dao.xml Sat Feb 11 14:57:45 2006
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<!--
+ Copyright 2004, 2005 The Apache Software Foundation
+
+ Licensed 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.
+-->
+
+<module id="timetracker.dao" version="1.0.0"
+ package="org.apache.tapestry.timetracker.dao">
+
+ <service-point id="ProjectDao" interface="ProjectDao" >
+ <invoke-factory service-id="hivemind.BuilderFactory">
+ <construct class="ProjectDao" autowire-services="false">
+ <set-service property="connection" service-id="timetracker.db.DerbyConnection" />
+ </construct>
+ </invoke-factory>
+ </service-point>
+
+</module>
\ No newline at end of file
Modified: jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/timetracker.db.xml
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/timetracker.db.xml?rev=377078&r1=377077&r2=377078&view=diff
==============================================================================
--- jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/timetracker.db.xml (original)
+++ jakarta/tapestry/trunk/examples/TimeTracker/src/context/WEB-INF/timetracker.db.xml Sat Feb 11 14:57:45 2006
@@ -50,6 +50,7 @@
<set property="initialSize" value="1" />
<set property="maxActive" value="2" />
<set property="maxWait" value="40000" />
+ <set property="username" value="trackadmin" />
<set property="poolPreparedStatements" value="true" />
<set property="maxOpenPreparedStatements" value="20" />
</construct>
Added: jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/dao/BaseDao.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/dao/BaseDao.java?rev=377078&view=auto
==============================================================================
--- jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/dao/BaseDao.java (added)
+++ jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/dao/BaseDao.java Sat Feb 11 14:57:45 2006
@@ -0,0 +1,49 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed 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.tapestry.timetracker.dao;
+
+import java.sql.Connection;
+
+
+/**
+ * Provides standard base methods.
+ *
+ * @author jkuhnert
+ */
+public class BaseDao
+{
+ /** jdbc connection. */
+ protected Connection _conn;
+
+ /** Default constructor. */
+ public BaseDao() { }
+
+ /**
+ * Injected connection.
+ * @param conn
+ */
+ public void setConnection(Connection conn)
+ {
+ _conn = conn;
+ }
+
+ /**
+ *
+ * @return The local connection being used.
+ */
+ public Connection getConnection()
+ {
+ return _conn;
+ }
+}
Added: jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/dao/ProjectDao.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/dao/ProjectDao.java?rev=377078&view=auto
==============================================================================
--- jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/dao/ProjectDao.java (added)
+++ jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/dao/ProjectDao.java Sat Feb 11 14:57:45 2006
@@ -0,0 +1,73 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed 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.tapestry.timetracker.dao;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tapestry.timetracker.model.Project;
+
+/**
+ * Manages db actions related to {@link Project} instances.
+ *
+ * @author jkuhnert
+ */
+public class ProjectDao extends BaseDao
+{
+
+ /**
+ * Default constructor.
+ */
+ public ProjectDao()
+ {
+ super();
+ }
+
+ /**
+ * Creates a list of all projects.
+ * @return
+ */
+ public List<Project> listProjects()
+ {
+ List<Project> ret = new ArrayList();
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+
+ try {
+ ps = _conn.prepareStatement("select project_id, name from projects");
+ rs = ps.executeQuery();
+
+ int x = 0;
+ while (rs.next()) {
+ x = 0;
+ Project pr = new Project();
+
+ pr.setId(rs.getLong(++x));
+ pr.setName(rs.getString(++x));
+
+ ret.add(pr);
+ }
+
+ return ret;
+
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ try { if (rs != null) rs.close(); } catch (Exception e) { }
+ try { if (ps != null) ps.close(); } catch (Exception e) { }
+ }
+ }
+}
Added: jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/model/Project.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/model/Project.java?rev=377078&view=auto
==============================================================================
--- jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/model/Project.java (added)
+++ jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/model/Project.java Sat Feb 11 14:57:45 2006
@@ -0,0 +1,72 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed 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.tapestry.timetracker.model;
+
+
+/**
+ * Represents a project for which time will be tracked.
+ *
+ * @author jkuhnert
+ */
+public class Project
+{
+ protected long _id;
+ protected String _name;
+
+ /** Default constructor. */
+ public Project() { }
+
+ /**
+ * Creates a new project with default values.
+ * @param id
+ * @param name
+ */
+ public Project(long id, String name)
+ {
+ _id = id;
+ _name = name;
+ }
+
+ /**
+ * @return Returns the id.
+ */
+ public long getId()
+ {
+ return _id;
+ }
+
+ /**
+ * @param id The id to set.
+ */
+ public void setId(long id)
+ {
+ _id = id;
+ }
+
+ /**
+ * @return Returns the name.
+ */
+ public String getName()
+ {
+ return _name;
+ }
+
+ /**
+ * @param name The name to set.
+ */
+ public void setName(String name)
+ {
+ _name = name;
+ }
+}
Added: jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/TaskEntryPage.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/TaskEntryPage.java?rev=377078&view=auto
==============================================================================
--- jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/TaskEntryPage.java (added)
+++ jakarta/tapestry/trunk/examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/TaskEntryPage.java Sat Feb 11 14:57:45 2006
@@ -0,0 +1,56 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed 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.tapestry.timetracker.page;
+
+import java.util.List;
+
+import org.apache.tapestry.annotations.Component;
+import org.apache.tapestry.annotations.InjectObject;
+import org.apache.tapestry.form.BeanPropertySelectionModel;
+import org.apache.tapestry.form.IPropertySelectionModel;
+import org.apache.tapestry.form.PropertySelection;
+import org.apache.tapestry.html.BasePage;
+import org.apache.tapestry.timetracker.dao.ProjectDao;
+import org.apache.tapestry.timetracker.model.Project;
+
+
+/**
+ * Manages entering tasks.
+ *
+ * @author jkuhnert
+ */
+public abstract class TaskEntryPage extends BasePage
+{
+
+ @Component(type = "PropertySelection", id = "projectChoose",
+ bindings = { "model=projectModel", "value=selectedProject",
+ "displayName=message:choose.project"})
+ public abstract PropertySelection getProjectSelection();
+
+ @InjectObject("service:timetracker.dao.ProjectDao")
+ public abstract ProjectDao getProjectDao();
+
+ public abstract Project getSelectedProject();
+
+ /**
+ * Selection model for projects.
+ * @return
+ */
+ public IPropertySelectionModel getProjectModel()
+ {
+ List<Project> projects = getProjectDao().listProjects();
+ projects.add(0, new Project(-1, "Choose.."));
+ return new BeanPropertySelectionModel(projects, "name");
+ }
+}
Modified: jakarta/tapestry/trunk/framework/build.xml
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/build.xml?rev=377078&r1=377077&r2=377078&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/build.xml (original)
+++ jakarta/tapestry/trunk/framework/build.xml Sat Feb 11 14:57:45 2006
@@ -38,7 +38,8 @@
<target name="compile-dependencies">
<ibiblio-dependency artifact="commons-codec" version="${codec.version}" group="commons-codec"/>
<ibiblio-dependency artifact="commons-fileupload" version="${fileupload.version}" group="commons-fileupload"/>
- <ibiblio-dependency artifact="commons-logging" version="${logging.version}" group="commons-logging"/>
+ <ibiblio-dependency artifact="commons-logging" version="${logging.version}" group="commons-logging"/>
+ <ibiblio-dependency artifact="commons-beanutils" version="${beanutils.version}" group="commons-beanutils"/>
<ibiblio-dependency artifact="hivemind" version="${hivemind.version}" group="hivemind"/>
<ibiblio-dependency artifact="hivemind-lib" version="${hivemind.version}" group="hivemind"/>
<ibiblio-dependency artifact="oro" version="${oro.version}" group="oro"/>
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/form/BeanPropertySelectionModel.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/form/BeanPropertySelectionModel.java?rev=377078&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/form/BeanPropertySelectionModel.java (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/form/BeanPropertySelectionModel.java Sat Feb 11 14:57:45 2006
@@ -0,0 +1,119 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed 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.tapestry.form;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.commons.beanutils.BeanUtils;
+
+
+/**
+ * This class is a property selection model for an object list.
+ * This is used in PropertySelection, MultiplePropertySelection or Palette tapestry components.
+ *
+ * For example, to use for a Hospital class, and have the labels be the hospital names.
+ * <code>
+ * List<Hospital> list = ...;
+ * return new BeanPropertySelectionModel(hospitals, "name");
+ * </code>
+ * This will use getName() on the Hospital object, as its display.
+ *
+ * @author Gabriel Handford
+ */
+public class BeanPropertySelectionModel implements IPropertySelectionModel, Serializable
+{
+
+ /** Comment for <code>serialVersionUID</code>. */
+ private static final long serialVersionUID = 3763091973006766644L;
+ private List _list;
+ private String _labelField;
+
+ /**
+ * Build an empty property selection model.
+ */
+ public BeanPropertySelectionModel() {
+ this(Arrays.asList(new Object[0]), null);
+ }
+
+ /**
+ * Build a bean property selection model.
+ * @param list The list
+ * @param labelField The label field
+ */
+ public BeanPropertySelectionModel(List list, String labelField) {
+ _list = list;
+ _labelField = labelField;
+ }
+
+ /**
+ * Build a bean property selection model.
+ * @param c Collection
+ * @param labelField The label field
+ */
+ public BeanPropertySelectionModel(Collection c, String labelField) {
+ _list = new ArrayList(c);
+ _labelField = labelField;
+ }
+
+ /**
+ * Get the number of options.
+ * @return option count
+ */
+ public int getOptionCount() { return _list.size(); }
+
+ /**
+ * Get the option at index.
+ * @param index Index
+ * @return object Object at index
+ */
+ public Object getOption(int index) {
+ return _list.get(index);
+ }
+
+ /**
+ * Get the label at index.
+ * @param index Index
+ * @return label Label at index
+ */
+ public String getLabel(int index) {
+ Object obj = _list.get(index);
+ try {
+ return BeanUtils.getProperty(obj, _labelField);
+ } catch (Exception e) {
+ throw new RuntimeException("Error getting property", e);
+ }
+ }
+
+ /**
+ * Get the value at index.
+ * @param index Index
+ * @return value Value at index
+ */
+ public String getValue(int index) {
+ return String.valueOf(index);
+ }
+
+ /**
+ * Translate value to object.
+ * @param value Value
+ * @return object Object from value
+ */
+ public Object translateValue(String value) {
+ return getOption(Integer.parseInt(value));
+ }
+}
Added: jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/form/BeanPropertySelectionModelTest.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/form/BeanPropertySelectionModelTest.java?rev=377078&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/form/BeanPropertySelectionModelTest.java (added)
+++ jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/form/BeanPropertySelectionModelTest.java Sat Feb 11 14:57:45 2006
@@ -0,0 +1,61 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed 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.tapestry.form;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.hivemind.test.HiveMindTestCase;
+
+
+/**
+ * Tests the functionality of {@link BeanPropertySelectionModel}.
+ *
+ * @author jkuhnert
+ */
+public class BeanPropertySelectionModelTest extends HiveMindTestCase
+{
+
+ /**
+ * Tests using a null arg constuctor.
+ */
+ public void testNullModel()
+ {
+ BeanPropertySelectionModel model = new BeanPropertySelectionModel();
+ assertEquals(model.getOptionCount(), 0);
+ }
+
+ /**
+ * Uses {@link BeanPropertySelectionModelTest} as the
+ * model.
+ */
+ public void testBasicModel()
+ {
+ List<SimpleBean> list = new ArrayList();
+ list.add(new SimpleBean(1, "Name 1", "Description 1"));
+ list.add(new SimpleBean(2, "Name 2", "Description 2"));
+ list.add(new SimpleBean(3, "Name 3", "Description 3"));
+
+ BeanPropertySelectionModel model =
+ new BeanPropertySelectionModel(list, "name");
+
+ assertEquals(model.getOptionCount(), 3);
+
+ SimpleBean b2 = (SimpleBean)model.getOption(1);
+ assertEquals(b2.getId(), 2);
+ assertEquals(model.getLabel(2), "Name 3");
+
+ assertEquals(model.translateValue("1"), b2);
+ }
+}
Added: jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/form/SimpleBean.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/form/SimpleBean.java?rev=377078&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/form/SimpleBean.java (added)
+++ jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/form/SimpleBean.java Sat Feb 11 14:57:45 2006
@@ -0,0 +1,69 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed 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.tapestry.form;
+
+
+/**
+ * Used by the {@link BeanPropertySelectionModelTest} to test
+ * listing/selecting bean properties.
+ *
+ * @author jkuhnert
+ */
+public class SimpleBean
+{
+
+ protected int _id;
+ protected String _name;
+ protected String _description;
+
+ /** Default constructor. */
+ public SimpleBean() { }
+
+ /**
+ * Creates a new instance with default values.
+ * @param id
+ * @param name
+ * @param description
+ */
+ public SimpleBean(int id, String name, String description)
+ {
+ _id = id;
+ _name = name;
+ _description = description;
+ }
+
+ /**
+ * @return Returns the description.
+ */
+ public String getDescription()
+ {
+ return _description;
+ }
+
+ /**
+ * @return Returns the id.
+ */
+ public int getId()
+ {
+ return _id;
+ }
+
+ /**
+ * @return Returns the name.
+ */
+ public String getName()
+ {
+ return _name;
+ }
+}
Modified: jakarta/tapestry/trunk/status.xml
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/status.xml?rev=377078&r1=377077&r2=377078&view=diff
==============================================================================
--- jakarta/tapestry/trunk/status.xml (original)
+++ jakarta/tapestry/trunk/status.xml Sat Feb 11 14:57:45 2006
@@ -63,7 +63,6 @@
<action type="add" dev="JK" fixes-bug="TAPESTRY-812" due-to="Takashi Okamoto">
Added japanese localized validator strings.
</action>
- <release version="4.1.0" date="unreleased">
<action type="update" dev="JK" >Cleaned up warnings/imports showing on eclipse problem pane.</action>
<action type="add" dev="JK" fixes-bug="TAPESTRY-821">ResourceMatcher service added with configurable regexp pattern
hivemind contributions to conditionally allow some resources to not
@@ -73,6 +72,10 @@
</action>
<action type="fix" dev="HLS" fixes-bug="TAPESTRY-787">Port late bug fixes from 4.0 branch to trunk</action>
<action type="update" dev="HLS">Add a checkstyle configuration for the project, and fix a number of related warnings and errors</action>
+ <action type="add" dev="JK" due-to="Gabriel Handford" >
+ Added a new utility implementation of IPropertySelectionModel that uses commons-beanutils to
+ select values from a standard POJO object.
+ </action>
</release>
<release version="4.0" date="Jan 6 2006">
<action type="update" dev="HLS">Add link to DeveloperWorks Tapestry article</action>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org