From seam-commits at lists.jboss.org Tue Mar 31 00:56:03 2009 Content-Type: multipart/mixed; boundary="===============2165602180059154530==" MIME-Version: 1.0 From: seam-commits at lists.jboss.org To: seam-commits at lists.jboss.org Subject: [seam-commits] Seam SVN: r10247 - in trunk: src/main/org/jboss/seam/faces and 1 other directory. Date: Tue, 31 Mar 2009 00:56:03 -0400 Message-ID: --===============2165602180059154530== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: dan.j.allen Date: 2009-03-31 00:56:03 -0400 (Tue, 31 Mar 2009) New Revision: 10247 Added: trunk/src/main/org/jboss/seam/faces/DateConverter.java Modified: trunk/doc/Seam_Reference_Guide/en-US/Components.xml trunk/doc/Seam_Reference_Guide/en-US/Events.xml trunk/doc/Seam_Reference_Guide/en-US/I18n.xml trunk/doc/Seam_Reference_Guide/en-US/Tutorial.xml Log: JBSEAM-3551 Modified: trunk/doc/Seam_Reference_Guide/en-US/Components.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/doc/Seam_Reference_Guide/en-US/Components.xml 2009-03-31 03:58:24= UTC (rev 10246) +++ trunk/doc/Seam_Reference_Guide/en-US/Components.xml 2009-03-31 04:56:03= UTC (rev 10247) @@ -55,15 +55,41 @@ = - = +
- Utility components + JSF-related components - These components are merely useful. + The following set of components are provided to supplement JSF. - = - + + + org.jboss.seam.faces.dateConverter + + + Provides a default JSF converter for properties of= type + java.util.Date. + + + + This converter is automatically registered with JS= F. It + is provided to save a developer from having to spe= cify + a DateTimeConverter on an input field or page + parameter. By default, it assumes the type to be a= date + (as opposed to a time or date plus time) and uses = the + short input style adjusted to the Locale of the us= er. + For Locale.US, the input pattern is mm/DD/yy. Howe= ver, + to comply with Y2K, the year is changed from two d= igits + to four (e.g., mm/DD/yyyy). + + + It's possible to override the input pattern global= ly + using component configuration. Consult the JavaDoc= for + this class to see examples. + + + + org.jboss.seam.faces.facesMessages @@ -166,6 +192,21 @@ + + + + These components are installed when the class javax.f= aces.context.FacesContext + is available on the classpath. + +
+ = +
+ Utility components + + These components are merely useful. + + = + org.jboss.seam.core.events Modified: trunk/doc/Seam_Reference_Guide/en-US/Events.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/doc/Seam_Reference_Guide/en-US/Events.xml 2009-03-31 03:58:24 UTC= (rev 10246) +++ trunk/doc/Seam_Reference_Guide/en-US/Events.xml 2009-03-31 04:56:03 UTC= (rev 10247) @@ -431,7 +431,8 @@ = Even better, model-based Hibernate validator annotations are a= utomatically - recognized and validated. + recognized and validated. Seam also provides a default date co= nverter to + convert a string parameter value to a date and back. = Modified: trunk/doc/Seam_Reference_Guide/en-US/I18n.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/doc/Seam_Reference_Guide/en-US/I18n.xml 2009-03-31 03:58:24 UTC (= rev 10246) +++ trunk/doc/Seam_Reference_Guide/en-US/I18n.xml 2009-03-31 04:56:03 UTC (= rev 10247) @@ -336,6 +336,11 @@ the Seam timezone. In addition, Seam provides the <s:convertDateTime> tag which always performs conversi= ons in the Seam timezone. + + Seam also provides a default date converter to convert a string = value + to a date. This saves you from having to specify a converter on input = fields + that are simply capturing a date. The pattern is selected according the + the user's locale and the time zone is selected as described above.
=
Modified: trunk/doc/Seam_Reference_Guide/en-US/Tutorial.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/doc/Seam_Reference_Guide/en-US/Tutorial.xml 2009-03-31 03:58:24 U= TC (rev 10246) +++ trunk/doc/Seam_Reference_Guide/en-US/Tutorial.xml 2009-03-31 04:56:03 U= TC (rev 10247) @@ -1437,6 +1437,8 @@ ]]> = + Seam provides a default JSF date converter for convertin= g a string to a date (no time). + Thus, the converter is not necessary for the field bound to #{task.dueDate}. = This button ends the task by calling the action method = annotated @StartTask @EndTask. It passes the task id to Seam as a req= uest parameter: Added: trunk/src/main/org/jboss/seam/faces/DateConverter.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/src/main/org/jboss/seam/faces/DateConverter.java = (rev 0) +++ trunk/src/main/org/jboss/seam/faces/DateConverter.java 2009-03-31 04:56= :03 UTC (rev 10247) @@ -0,0 +1,120 @@ +package org.jboss.seam.faces; + +import static org.jboss.seam.annotations.Install.BUILT_IN; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; + +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.ConverterException; + +import org.jboss.seam.annotations.Create; +import org.jboss.seam.annotations.Install; +import org.jboss.seam.annotations.Name; +import org.jboss.seam.annotations.faces.Converter; +import org.jboss.seam.annotations.intercept.BypassInterceptors; +import org.jboss.seam.contexts.Contexts; +import org.jboss.seam.log.Log; +import org.jboss.seam.log.Logging; + +/** + * Provides a default JSF converter for properties of type java.util.Date. + * = + *

This converter is provided to save a developer from having to specify + * a DateTimeConverter on an input field or page parameter. By default, it + * assumes the type to be a date (as opposed to a time or date plus time) = and + * uses the short input style adjusted to the Locale of the user. For Loca= le.US, + * the input pattern is mm/DD/yy. However, to comply with Y2K, the year is= changed + * from two digits to four (e.g., mm/DD/yyyy).

+ *

It's possible to override the input pattern globally using component= configuration. + * Here is an example of changing the style to both and setting the date a= nd + * time style to medium.

+ *
+ * org.jboss.seam.faces.dateConverter.type=3Dboth
+ * org.jboss.seam.faces.dateConverter.dateStyle=3Dmedium
+ * org.jboss.seam.faces.dateConverter.timeStyle=3Dmedium
+ * 
+ *

Alternatively, a fixed pattern can be specified.

+ *
+ * org.jboss.seam.faces.dateConverter.pattern=3Dyyyy-mm-DD
+ * 
+ * = + * @author Dan Allen + */ +(a)Converter(forClass =3D Date.class) +(a)Name("org.jboss.seam.faces.dateConverter") +(a)Install(precedence =3D BUILT_IN, classDependencies =3D "javax.faces.con= text.FacesContext") +(a)BypassInterceptors +public class DateConverter extends javax.faces.convert.DateTimeConverter { + + private Log log =3D Logging.getLog(DateConverter.class); + + private static final String TYPE_DATE =3D "date"; + private static final String STYLE_SHORT =3D "short"; + private static final String TWO_DIGIT_YEAR_PATTERN =3D "yy"; + private static final String FOUR_DIGIT_YEAR_PATTERN =3D "yyyy"; + = + // constructor is used to initialize converter to allow these values to b= e overridden using component properties + public DateConverter() { + super(); + setType(TYPE_DATE); + setDateStyle(STYLE_SHORT); + setTimeStyle(STYLE_SHORT); // default in case developer overrides type t= o be time or both + } + = + @Create + public void create() { + // TODO make this work if using "both" for type; requires more analysis = of time style + if (TYPE_DATE.equals(getType()) && STYLE_SHORT.equals(getDateStyle()) &&= getPattern() =3D=3D null) { + // attempt to make the pattern Y2K compliant, which it isn't by default + DateFormat dateFormat =3D DateFormat.getDateInstance(DateFormat.SHORT, = getLocale()); + if (dateFormat instanceof SimpleDateFormat) { + setPattern(((SimpleDateFormat) dateFormat).toPattern().replace(TWO_DIG= IT_YEAR_PATTERN, FOUR_DIGIT_YEAR_PATTERN)); + } + } + // required since the superclass may access the fields directly + setTimeZone(getTimeZone()); + setLocale(getLocale()); + } + + @Override + public TimeZone getTimeZone() { + if (Contexts.isApplicationContextActive()) { + return org.jboss.seam.international.TimeZone.instance(); + } else { + // we don't want to use JSF's braindead default (maybe in JSF 2) + return TimeZone.getDefault(); + } + } + + @Override + public Locale getLocale() { + if (Contexts.isApplicationContextActive()) { + return org.jboss.seam.international.Locale.instance(); + } else { + return super.getLocale(); + } + } + + @Override + public Object getAsObject(FacesContext context, UIComponent component, + String value) throws ConverterException { + if (log.isDebugEnabled()) { + log.debug("Converting string '#0' to date for clientId '#1' using Seam'= s built-in JSF date converter", value, component.getClientId(context)); + } + return super.getAsObject(context, component, value); + } + + @Override + public String getAsString(FacesContext context, UIComponent component, + Object value) throws ConverterException { + if (log.isDebugEnabled()) { + log.debug("Converting date '#0' to string for clientId '#1' using Seam'= s built-in JSF date converter", value, component.getClientId(context)); + } + return super.getAsString(context, component, value); + } +} --===============2165602180059154530==--