The First Day of the Week"
Line 1: | Line 1: | ||
{{ZKDevelopersReferencePageHeader}} | {{ZKDevelopersReferencePageHeader}} | ||
− | By default, the first day of | + | =Overview= |
+ | By default, the first day of week depends on the locale (e.g., Sunday in US, Monday in France). More precisely, it is the value returned by the <tt>getFirstDayOfWeek</tt> method of the <tt>java.util.Calendar</tt> class. | ||
− | However, you can configure it different | + | However, you can configure it different, and it will affect how [http://books.zkoss.org/wiki/ZK_Component_Reference/Input/Datebox datebox] and [http://books.zkoss.org/wiki/ZK_Component_Reference/Input/Calendar calendar] components behave. |
− | === | + | =The decision sequence of the first day of week= |
+ | The first day of week is decided in the following sequence. | ||
+ | |||
+ | # It checks if an attribute called <code>org.zkoss.web.preferred.firstDayOfWeek</code> defined in the HTTP session (aka., <javadoc type="interface">org.zkoss.zk.ui.Session</javadoc>). If so, use it. | ||
+ | # It checks if an attribute called <code>org.zkoss.web.preferred.firstDayOfWeek</code> defined in the Servlet context (aka., <javadoc type="interface">org.zkoss.zk.ui.Application</javadoc>). If so, use it. | ||
+ | # It checks if a property called <code>org.zkoss.web.preferred.firstDayOfWeek</code> defined in the library property (i.e., <javadoc>org.zkoss.lang.Library</javadoc>). If so, use it. | ||
+ | # If none of them is found, JVM's default will be used (<tt>java.util.Calendar</tt>). | ||
+ | |||
+ | ==Application-level first-day-of-week== | ||
[since 5.0.3] | [since 5.0.3] | ||
− | + | If you want to use the same first-day-of-week for all users of the same application, you can specify it in the library property. | |
− | The allowed | + | The allowed values include 1 (Sunday), 2 (Monday), .. and 7 (Saturday). For example, you could specify the following in <tt>WEB-INF/zk.xml</tt>: |
− | <source lang=" | + | <source lang="xml"> |
− | + | <library-property> | |
− | + | <name>org.zkoss.web.preferred.firstDayOfWeek</name> | |
+ | <value>7</value><!-- Saturday --> | ||
+ | </library-property> | ||
</source> | </source> | ||
− | === | + | Alternatively, if you prefer to specify it in Java, you could invoke <javadoc method="setProperty(java.lang.String, java.lang.String)">org.zkoss.lang.Library</javadoc>. Furthermore, to avoid typo, you could use <javadoc method="setAttribute(java.lang.String, java.lang.Object)" type="interface">org.zkoss.zk.ui.WebApp</javadoc> and <javadoc method="PREFERRED_FIRST_DAY_OF_WEEK">org.zkoss.web.Attributes</javadoc> as follows. |
− | + | When using <javadoc method="setAttribute(java.lang.String, java.lang.Object)" type="interface">org.zkoss.zk.ui.WebApp</javadoc>, the allowed value include Calendar.SUNDAY, Calendar.MONDAY and so on. | |
− | + | <source lang="java"> | |
− | + | webApp.setAttribute(org.zkoss.web.Attributes.PREFERRED_FIRST_DAY_OF_WEEK, java.util.Calendar.SATURDAY); | |
+ | </source> | ||
− | + | == Per-user first-day-of-week == | |
− | |||
− | == | ||
[since 5.0.3] | [since 5.0.3] | ||
− | By specify a value to the | + | By specify a value to the session attribute called <tt>org.zkoss.web.preferred.firstDayOfWeek</tt> (i.e., <javadoc method="PREFERRED_FIRST_DAY_OF_WEEK">org.zkoss.web.Attributes</javadoc>), you can control the first day of the week for the give session. |
− | The allowed | + | The allowed value include Calendar.SUNDAY, Calendar.MONDAY and so on. |
− | + | <source lang="java"> | |
+ | session.setAttribute(org.zkoss.web.Attributes.PREFERRED_FIRST_DAY_OF_WEEK, java.util.Calendar.SATURDAY); | ||
+ | //then, the current session's first day of the week will be Saturday | ||
+ | </source> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=Version History= | =Version History= |
Revision as of 10:39, 11 October 2010
Overview
By default, the first day of week depends on the locale (e.g., Sunday in US, Monday in France). More precisely, it is the value returned by the getFirstDayOfWeek method of the java.util.Calendar class.
However, you can configure it different, and it will affect how datebox and calendar components behave.
The decision sequence of the first day of week
The first day of week is decided in the following sequence.
- It checks if an attribute called
org.zkoss.web.preferred.firstDayOfWeek
defined in the HTTP session (aka., Session). If so, use it. - It checks if an attribute called
org.zkoss.web.preferred.firstDayOfWeek
defined in the Servlet context (aka., Application). If so, use it. - It checks if a property called
org.zkoss.web.preferred.firstDayOfWeek
defined in the library property (i.e., Library). If so, use it. - If none of them is found, JVM's default will be used (java.util.Calendar).
Application-level first-day-of-week
[since 5.0.3]
If you want to use the same first-day-of-week for all users of the same application, you can specify it in the library property. The allowed values include 1 (Sunday), 2 (Monday), .. and 7 (Saturday). For example, you could specify the following in WEB-INF/zk.xml:
<library-property>
<name>org.zkoss.web.preferred.firstDayOfWeek</name>
<value>7</value><!-- Saturday -->
</library-property>
Alternatively, if you prefer to specify it in Java, you could invoke Library.setProperty(String, String). Furthermore, to avoid typo, you could use WebApp.setAttribute(String, Object) and Attributes.PREFERRED_FIRST_DAY_OF_WEEK as follows.
When using WebApp.setAttribute(String, Object), the allowed value include Calendar.SUNDAY, Calendar.MONDAY and so on.
webApp.setAttribute(org.zkoss.web.Attributes.PREFERRED_FIRST_DAY_OF_WEEK, java.util.Calendar.SATURDAY);
Per-user first-day-of-week
[since 5.0.3]
By specify a value to the session attribute called org.zkoss.web.preferred.firstDayOfWeek (i.e., Attributes.PREFERRED_FIRST_DAY_OF_WEEK), you can control the first day of the week for the give session. The allowed value include Calendar.SUNDAY, Calendar.MONDAY and so on.
session.setAttribute(org.zkoss.web.Attributes.PREFERRED_FIRST_DAY_OF_WEEK, java.util.Calendar.SATURDAY);
//then, the current session's first day of the week will be Saturday
Version History
Last Update : 2010/10/11
Version | Date | Content |
---|---|---|