Home   Single Page

px_preferred_localセッション属性

ブラウザの環境設定(preference)をチェックする前に、ZKはpx_preferred_localeと呼ばれるセッションが定義されたかどかを確認します。
定義されていたら、ZKはブラウザの環境設定の代わりにセッションにデフォルトロケールとしてそれを使用します
。これによって、この属性の中で好みのロケールを設定することで、セッションのロケールを決められます。

以下は、ユーザーがログインするときに使用する例です。

Before checking the browser's preferences, ZK will check if a session attribute called px_preferred_locale is defined. If defined, ZK uses it as the default locale for the session instead of the browser's preferences. Thus, you can control the locale of a session by storing the preferred locale in this attribute.

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

void login(String username, String password) {
    //check password    
    ...    
    Locale preferredLocale = ...; //decide the locale (from, say, database)    
    session.setAttribute("px_preferred_locale", preferredLocale);    
    ...    
}

【ヒント】:org.zkoss.web.Attributesクラスの中でPREFERRED_LOCALEと呼ばれる定数を使用すれば。誤植を避けることができます。