I wonder if this could have been accomplished more easily by a) mapping java.util.Calendar to data type "date" b) providing TypeCoercions to and from Calendar and Date
I suspect that would have worked with a bit less code. On Sun, Jul 26, 2009 at 3:32 PM, <[email protected]> wrote: > Author: drobiazko > Date: Sun Jul 26 22:32:06 2009 > New Revision: 797996 > > URL: http://svn.apache.org/viewvc?rev=797996&view=rev > Log: > TAP5-789: Provide bean and display blocks for java.util.Calendar > > Added: > > tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BeanEditCalendarDemo.tml > tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ShowCalendarHolder.tml > > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/data/CalendarHolder.java > (with props) > > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BeanEditCalendarDemo.java > (with props) > > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ShowCalendarHolder.java > (with props) > Modified: > tapestry/tapestry5/trunk/src/site/apt/guide/beaneditform.apt > > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/PropertyDisplayBlocks.java > > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/PropertyEditBlocks.java > > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java > > tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/PropertyDisplayBlocks.tml > > tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/PropertyEditBlocks.tml > > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java > > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java > > Modified: tapestry/tapestry5/trunk/src/site/apt/guide/beaneditform.apt > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/src/site/apt/guide/beaneditform.apt?rev=797996&r1=797995&r2=797996&view=diff > ============================================================================== > --- tapestry/tapestry5/trunk/src/site/apt/guide/beaneditform.apt (original) > +++ tapestry/tapestry5/trunk/src/site/apt/guide/beaneditform.apt Sun Jul 26 > 22:32:06 2009 > @@ -25,6 +25,8 @@ > * Boolean: as a checkbox > > * Date: as a JavaScript calendar > + > + * Calendar: as a JavaScript calendar > > [] > > > Modified: > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/PropertyDisplayBlocks.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/PropertyDisplayBlocks.java?rev=797996&r1=797995&r2=797996&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/PropertyDisplayBlocks.java > (original) > +++ > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/PropertyDisplayBlocks.java > Sun Jul 26 22:32:06 2009 > @@ -22,6 +22,8 @@ > import org.apache.tapestry5.services.PropertyOutputContext; > > import java.text.DateFormat; > +import java.util.Calendar; > +import java.util.Date; > import java.util.Locale; > > public class PropertyDisplayBlocks > @@ -47,6 +49,13 @@ > { > return dateFormat; > } > + > + public Date getCalendarDate() > + { > + Calendar calendar = (Calendar) context.getPropertyValue(); > + return calendar.getTime(); > + } > + > > public PropertyOutputContext getContext() > { > > Modified: > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/PropertyEditBlocks.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/PropertyEditBlocks.java?rev=797996&r1=797995&r2=797996&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/PropertyEditBlocks.java > (original) > +++ > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/pages/PropertyEditBlocks.java > Sun Jul 26 22:32:06 2009 > @@ -69,6 +69,12 @@ > parameters = {"value=context.propertyValue", > "label=prop:context.label", "clientId=prop:context.propertyid", > "validate=prop:dateFieldValidator"}) > private DateField dateField; > + > + �...@suppresswarnings("unused") > + �...@component( > + parameters = {"value=context.propertyValue", > "label=prop:context.label", "clientId=prop:context.propertyid", > + "validate=prop:calendarFieldValidator"}) > + private DateField calendarField; > > @Component( > parameters = {"value=context.propertyValue", > "label=prop:context.label", > @@ -136,6 +142,11 @@ > return context.getValidator(dateField); > } > > + public FieldValidator getCalendarFieldValidator() > + { > + return context.getValidator(calendarField); > + } > + > public FieldValidator getSelectValidator() > { > return context.getValidator(select); > > Modified: > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=797996&r1=797995&r2=797996&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java > (original) > +++ > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java > Sun Jul 26 22:32:06 2009 > @@ -570,6 +570,7 @@ > configuration.add(Enum.class, "enum"); > configuration.add(Boolean.class, "boolean"); > configuration.add(Date.class, "date"); > + configuration.add(Calendar.class, "calendar"); > } > > public static void > contributeBeanBlockSource(Configuration<BeanBlockContribution> configuration) > @@ -580,6 +581,7 @@ > addEditBlock(configuration, "boolean"); > addEditBlock(configuration, "date"); > addEditBlock(configuration, "password"); > + addEditBlock(configuration, "calendar"); > > // longtext uses a text area, not a text field > > @@ -587,6 +589,7 @@ > > addDisplayBlock(configuration, "enum"); > addDisplayBlock(configuration, "date"); > + addDisplayBlock(configuration, "calendar"); > > // Password and long text have special output needs. > addDisplayBlock(configuration, "password"); > @@ -1000,6 +1003,16 @@ > }); > > add(configuration, PrimaryKeyEncoder.class, ValueEncoder.class, new > PrimaryKeyEncoder2ValueEncoder(coercer)); > + > + add(configuration, Date.class, Calendar.class, new Coercion<Date, > Calendar>() > + { > + public Calendar coerce(Date input) > + { > + Calendar calendar = > Calendar.getInstance(threadLocale.getLocale()); > + calendar.setTime(input); > + return calendar; > + } > + }); > } > > /** > > Modified: > tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/PropertyDisplayBlocks.tml > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/PropertyDisplayBlocks.tml?rev=797996&r1=797995&r2=797996&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/PropertyDisplayBlocks.tml > (original) > +++ > tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/PropertyDisplayBlocks.tml > Sun Jul 26 22:32:06 2009 > @@ -6,6 +6,10 @@ > > <t:block id="date"> > <t:output value="context.propertyValue" format="dateFormat"/> > + </t:block> > + > + <t:block id="calendar"> > + <t:output value="calendarDate" format="dateFormat"/> > </t:block> > > <t:block id="password"> > > Modified: > tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/PropertyEditBlocks.tml > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/PropertyEditBlocks.tml?rev=797996&r1=797995&r2=797996&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/PropertyEditBlocks.tml > (original) > +++ > tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/pages/PropertyEditBlocks.tml > Sun Jul 26 22:32:06 2009 > @@ -24,6 +24,11 @@ > <t:block id="date"> > <t:label for="dateField"/> > <input t:id="dateField"/> > + </t:block> > + > + <t:block id="calendar"> > + <t:label for="calendarField"/> > + <input t:id="calendarField"/> > </t:block> > > <t:block id="password"> > > Added: > tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BeanEditCalendarDemo.tml > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BeanEditCalendarDemo.tml?rev=797996&view=auto > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BeanEditCalendarDemo.tml > (added) > +++ > tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BeanEditCalendarDemo.tml > Sun Jul 26 22:32:06 2009 > @@ -0,0 +1,13 @@ > +<html t:type="Border" > + xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"> > + > + <h1>BeanEditor Calendar Demo</h1> > + > + <t:beaneditform t:id="holder" /> > + > + <hr /> > + > + <t:actionlink t:id="clear">clear</t:actionlink> > + > + > +</html> > > Added: > tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ShowCalendarHolder.tml > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ShowCalendarHolder.tml?rev=797996&view=auto > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ShowCalendarHolder.tml > (added) > +++ > tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ShowCalendarHolder.tml > Sun Jul 26 22:32:06 2009 > @@ -0,0 +1,8 @@ > +<html t:type="Border" > + xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"> > + > + <h1>BeanEditor Calendar Demo</h1> > + > + <t:beandisplay object="holder" /> > + > +</html> > > Modified: > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java?rev=797996&r1=797995&r2=797996&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java > (original) > +++ > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java > Sun Jul 26 22:32:06 2009 > @@ -3120,4 +3120,16 @@ > assertTextPresent("read Foo"); > assertTextPresent("read Bar"); > } > + > + �...@test > + public void calendar_field_inside_bean_editor() > + { > + start("BeanEditor / Calendar Demo", "clear"); > + > + type("calendar", "04/06/1978"); > + > + clickAndWait(SUBMIT); > + > + assertTextPresent("Apr 6, 1978"); > + } > } > > Added: > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/data/CalendarHolder.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/data/CalendarHolder.java?rev=797996&view=auto > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/data/CalendarHolder.java > (added) > +++ > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/data/CalendarHolder.java > Sun Jul 26 22:32:06 2009 > @@ -0,0 +1,35 @@ > +// Copyright 2009 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.tapestry5.integration.app1.data; > + > +import java.util.Calendar; > + > +import org.apache.tapestry5.beaneditor.Validate; > + > +public class CalendarHolder > +{ > + private Calendar calendar; > + > + �...@validate("required") > + public Calendar getCalendar() > + { > + return calendar; > + } > + > + public void setCalendar(Calendar calendar) > + { > + this.calendar = calendar; > + } > +} > > Propchange: > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/data/CalendarHolder.java > ------------------------------------------------------------------------------ > svn:eol-style = native > > Added: > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BeanEditCalendarDemo.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BeanEditCalendarDemo.java?rev=797996&view=auto > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BeanEditCalendarDemo.java > (added) > +++ > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BeanEditCalendarDemo.java > Sun Jul 26 22:32:06 2009 > @@ -0,0 +1,36 @@ > +// Copyright 2009 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.tapestry5.integration.app1.pages; > + > +import org.apache.tapestry5.annotations.Property; > +import org.apache.tapestry5.annotations.SessionState; > +import org.apache.tapestry5.integration.app1.data.CalendarHolder; > + > +public class BeanEditCalendarDemo > +{ > + �...@sessionstate > + �...@property > + private CalendarHolder holder; > + > + void onActionFromClear() > + { > + holder = null; > + } > + > + Object onSuccess() > + { > + return ShowCalendarHolder.class; > + } > +} > > Propchange: > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BeanEditCalendarDemo.java > ------------------------------------------------------------------------------ > svn:eol-style = native > > Modified: > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java?rev=797996&r1=797995&r2=797996&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java > (original) > +++ > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java > Sun Jul 26 22:32:06 2009 > @@ -379,7 +379,10 @@ > > new Item("SessionAttributeDemo", > "SessionAttribute Demo", > - "Annotation to map a field to a specific session > attribute") > + "Annotation to map a field to a specific session > attribute"), > + > + new Item("BeanEditCalendarDemo", "BeanEditor / Calendar Demo", > + "Use of calendar properties inside BeanEditor and > BeanDisplay") > > ); > > > Added: > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ShowCalendarHolder.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ShowCalendarHolder.java?rev=797996&view=auto > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ShowCalendarHolder.java > (added) > +++ > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ShowCalendarHolder.java > Sun Jul 26 22:32:06 2009 > @@ -0,0 +1,27 @@ > +// Copyright 2009 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.tapestry5.integration.app1.pages; > + > +import org.apache.tapestry5.annotations.Property; > +import org.apache.tapestry5.annotations.SessionState; > +import org.apache.tapestry5.integration.app1.data.CalendarHolder; > + > +public class ShowCalendarHolder > +{ > + �...@sessionstate > + �...@property > + private CalendarHolder holder; > + > +} > > Propchange: > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ShowCalendarHolder.java > ------------------------------------------------------------------------------ > svn:eol-style = native > > > -- Howard M. Lewis Ship Creator of Apache Tapestry Director of Open Source Technology at Formos --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
