The First Day of the Week"

From Documentation
m (remove empty version history (via JWB))
 
(18 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{ZKDevelopersGuidePageHeader}}
+
{{ZKDevelopersReferencePageHeader}}
  
By default, the first day of the week depends on the locale (e.g., Sunday in US, Monday in France). In fact, it is the value returned by the <tt>getFirstDayOfWeek</tt> method of the <tt>java.util.Calendar</tt> class.
+
=Overview=
 +
By default, the first day of the week depends on the locale (e.g., Sunday in US, Monday in France). More precisely, it is the value returned by the <code>getFirstDayOfWeek</code> method of the <code>java.util.Calendar</code> class.
  
However, you can configure it different as follows, 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.
+
However, you can configure it differently, and it will affect how [[ZK_Component_Reference/Input/Datebox|datebox]] and [[ZK_Component_Reference/Input/Calendar|calendar]] components behave.
  
=== The Session Attribute: <tt>org.zkoss.web.preferred.firstDayOfWeek</tt> ===
+
=The decision sequence of the first day of the week=
 +
The first day of the week is decided in the following sequence.
  
[since 5.0.3]
+
# It checks if an attribute called <code>org.zkoss.web.preferred.firstDayOfWeek</code> is 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> is 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> is 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 (<code>java.util.Calendar</code>).
  
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.
+
==Application-level first-day-of-the-week==
The allowed value include Calendar.SUNDAY, Calendar.MONDAY and so on.
+
 
 +
{{versionSince|5.0.3}}
 +
 
 +
If you want to use the same first-day-of-the-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 <code>WEB-INF/zk.xml</code>:
 +
 
 +
<source lang="xml">
 +
<library-property>
 +
    <name>org.zkoss.web.preferred.firstDayOfWeek</name>
 +
    <value>7</value><!-- Saturday -->
 +
</library-property>
 +
</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 typos, 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.
  
 
<source lang="java">
 
<source lang="java">
session.setAttribute(org.zkoss.web.Attributes.PREFERRED_FIRST_DAY_OF_WEEK, java.util.Calendar.SATURDAY);
+
webApp.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>
 
</source>
  
=== The Application Attribute: <tt>org.zkoss.web.preferred.firstDayOfWeek</tt> ===
+
As shown above, the allowed values of <javadoc method="setAttribute(java.lang.String, java.lang.Object)" type="interface">org.zkoss.zk.ui.WebApp</javadoc> include Calendar.SUNDAY, Calendar.MONDAY and so on.
  
[since 5.0.3]
+
== Per-user first-day-of-week ==
  
By specify a value to the <javadoc type="interface">org.zkoss.zk.ui.WebApp</javadoc> 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 whole application.
+
{{versionSince|5.0.3}}
The allowed value include Calendar.SUNDAY, Calendar.MONDAY and so on.
 
  
The session attribute has the higher priority than this.
+
By specifying a value to the session attribute called <code>org.zkoss.web.preferred.firstDayOfWeek</code> (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 given session.
 +
The allowed values include Calendar.SUNDAY, Calendar.MONDAY and so on.
  
=== The Library Property: <tt>org.zkoss.web.preferred.firstDayOfWeek</tt> ===
+
<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>
  
[since 5.0.3]
+
For example, you can do this when a user logins.
  
By specify a value to the library property 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 whole application.
+
<source lang="java" >
The allowed values include 1 (Sunday), 2 (Monday), .. and 7 (Saturday).
+
void login(String username, String password) {
 +
    //check password
 +
    ...
 +
    int preferredFDOW = ...; //decide the user's preference
 +
    session.setAttribute(Attributes.PREFERRED_FIRST_DAY_OF_WEEK, preferredFDOW);
 +
...
 +
</source>
  
The session and application attributes have higher priority than this.
 
  
<source lang="xml">
 
<library-property>
 
<name>org.zkoss.web.preferred.firstDayOfWeek</name>
 
<value>7</value> <!-- 7: Saturday -->
 
</library-property>
 
</source>
 
  
{{ ZKDevelopersGuidePageFooter}}
+
{{ZKDevelopersReferencePageFooter}}

Latest revision as of 04:36, 5 February 2024


The First Day of the Week


Overview

By default, the first day of the 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 differently, and it will affect how datebox and calendar components behave.

The decision sequence of the first day of the week

The first day of the week is decided in the following sequence.

  1. It checks if an attribute called org.zkoss.web.preferred.firstDayOfWeek is defined in the HTTP session (aka., Session). If so, use it.
  2. It checks if an attribute called org.zkoss.web.preferred.firstDayOfWeek is defined in the Servlet context (aka., Application). If so, use it.
  3. It checks if a property called org.zkoss.web.preferred.firstDayOfWeek is defined in the library property (i.e., Library). If so, use it.
  4. If none of them is found, JVM's default will be used (java.util.Calendar).

Application-level first-day-of-the-week

Since 5.0.3

If you want to use the same first-day-of-the-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 typos, you could use WebApp.setAttribute(String, Object) and Attributes.PREFERRED_FIRST_DAY_OF_WEEK as follows.

webApp.setAttribute(org.zkoss.web.Attributes.PREFERRED_FIRST_DAY_OF_WEEK, java.util.Calendar.SATURDAY);

As shown above, the allowed values of WebApp.setAttribute(String, Object) include Calendar.SUNDAY, Calendar.MONDAY and so on.

Per-user first-day-of-week

Since 5.0.3

By specifying 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 given session. The allowed values 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

For example, you can do this when a user logins.

 void login(String username, String password) {
     //check password
     ...
     int preferredFDOW = ...; //decide the user's preference
     session.setAttribute(Attributes.PREFERRED_FIRST_DAY_OF_WEEK, preferredFDOW);
...




Last Update : 2024/02/05

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.