【发布时间】:2010-11-11 13:16:36
【问题描述】:
标记:
<h:head>
<title>title</title>
</h:head>
<h:body>
<h:form>
<h:outputText value="#{viewScopeBacking.date}">
<f:convertDateTime timeZone="#{viewScopeBacking.timeZone}"/>
</h:outputText>
<h:commandButton action="#{viewScopeBacking.action}" value="submit">
<f:ajax event="action" render="op"/>
</h:commandButton>
<h:outputText value="#{viewScope.view}" id="op"/>
</h:form>
</h:body>
</html>
支持 bean:
@ManagedBean
@RequestScoped
public class viewScopeBacking {
public viewScopeBacking() {
}
@ManagedProperty(value = "#{viewScope}")
Map<String, Object> viewMap;
private Date date = new Date();
private TimeZone timeZone = TimeZone.getDefault();
public void action() {
getViewMap().put("view", "hello world");
}
//getters and setters
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public TimeZone getTimeZone() {
return timeZone;
}
public void setTimeZone(TimeZone timeZone) {
this.timeZone = timeZone;
}
public Map<String, Object> getViewMap() {
return viewMap;
}
public void setViewMap(Map<String, Object> viewMap) {
this.viewMap = viewMap;
}
}
按下按钮后,输出文本应按理论更新。但在您删除 convertDateTime 的 timeZone 属性之前,这不会发生。
【问题讨论】:
-
这个 [java] and [c] and [.net] 怎么样?
-
但是您在标签中添加了 C 和 NET。它们在这个问题中没有任何意义,所以 Marc 删除了它们(我用 JSF 标记替换了 JSP 标记,因为你根本没有使用 JSP,而是使用 Facelets)