viewScope与timeZone属性的奇怪行为

时间:2010-11-11 13:16:37

标签: java jsf jsf-2

标记:

         

    <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;
    }
}

按下按钮后,应按理论更新outputText。但是除非你删除convertDateTime的timeZone属性,否则不会发生这种情况。

1 个答案:

答案 0 :(得分:0)

使用<f:convertDateTime timeZone="#{Application.timeZone}"/>

而不是你的ManagedBean。

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

欢呼声