国际化rich:calendar控件——面板显示中文

1.通过locale进行中文化定义。

<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"> <rich:panel id="calendarPanel" bodyClass="rich-laguna-panel-no-header"> <a4j:outputPanel id="calendar" layout="block"> 查询日期 <rich:calendar value="#{calendarBean.selectedDate}" locale="#{calendarBean.locale}" popup="#{calendarBean.popup}" datePattern="#{calendarBean.pattern}" showApplyButton="#{calendarBean.showApply}" cellWidth="26px" cellHeight="22px" style="width:300px" /> </a4j:outputPanel> </rich:panel> </ui:composition>

2.后台的javabean

package com.skyteam.monitor.view; import java.util.Date; import java.util.Locale; import javax.faces.event.ValueChangeEvent; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; @Controller("calendarBean") @Scope("session") public class CalendarBean { private Locale locale; private boolean popup=true; private String pattern; private Date selectedDate; private boolean showApply=true; private boolean useCustomDayLabels; public Locale getLocale() { return locale; } public void setLocale(Locale locale) { this.locale = locale; } public boolean isPopup() { return popup; } public void setPopup(boolean popup) { this.popup = popup; } public String getPattern() { return pattern; } public void setPattern(String pattern) { this.pattern = pattern; } public CalendarBean() { locale = Locale.CHINA; popup = true; pattern = "yyyy-MM-dd"; } public void selectLocale(ValueChangeEvent event) { String tLocale = (String) event.getNewValue(); if (tLocale != null) { String lang = tLocale.substring(0, 2); String country = tLocale.substring(3); locale = new Locale(lang, country, ""); } } public boolean isUseCustomDayLabels() { return useCustomDayLabels; } public void setUseCustomDayLabels(boolean useCustomDayLabels) { this.useCustomDayLabels = useCustomDayLabels; } public Date getSelectedDate() { return selectedDate; } public void setSelectedDate(Date selectedDate) { this.selectedDate = selectedDate; } public boolean isShowApply() { return showApply; } public void setShowApply(boolean showApply) { this.showApply = showApply; } }

3.面板部分按钮信息中文化定义:在classpath下添加一个资源文件messages_zh_CN.properties,把相关内容设置一下

RICH_CALENDAR_TODAY_LABEL = 今天 RICH_CALENDAR_CLOSE_LABEL = 关闭 RICH_CALENDAR_OK_LABEL = 确定 RICH_CALENDAR_CLEAN_LABEL = 清空 RICH_CALENDAR_CANCEL_LABEL = 取消 RICH_CALENDAR_APPLY_LABEL = 确定

 

你可能感兴趣的:(UI,Date,String,session,calendar,layout)