【问题标题】:Strange behaviour of viewScope with timeZone attribute具有 timeZone 属性的 viewScope 的奇怪行为
【发布时间】: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)

标签: java jsf jsf-2


【解决方案1】:

使用&lt;f:convertDateTime timeZone="#{Application.timeZone}"/&gt;

而不是您的 ManagedBean。

至少这解决了我的问题。如果您知道原因,请告诉我。

干杯

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-27
    相关资源
    最近更新 更多