我在 DataTable 组件中使用 convertDateTime 标记。将托管 bean 属性连接到时区属性。在这种情况下,每个 ajax 都会请求重新创建托管 Bean。
托管 Bean 范围是 View Scoped。
<h:column>
<f:facet name="header">
<h:outputLabel value="Date"/>
</f:facet>
<h:outputText value="#{item.date}">
<f:convertDateTime timeZone="#{myBean.timezone}" locale="tr" pattern="dd.MM.yyyy"/>
</h:outputText>
</h:column>
@ManagedBean(name="myBean")
@ViewScoped
public class MyBean {
@PostConstruct
public void initBeanMethod(){
System.out.println("PostConstruct method is called...");
}
private TimeZone timezone = TimeZone.getDefault();
public TimeZone getTimezone() {
return timezone;
}
public void setTimezone(TimeZone timezone) {
this.timezone = timezone;
}
在每个 ajax 请求之后显示以下输出:“调用 PostConstruct 方法...”
你对每个请求都重新创建 bean 有什么想法吗?
注意:我为我糟糕的英语道歉:)