代码之家  ›  专栏  ›  技术社区  ›  siva636

带有时区属性的ViewScope的奇怪行为

  •  0
  • siva636  · 技术社区  · 16 年前

    Markup:

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

    支撑豆:

    @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的时区属性之前,不会发生这种情况。

    1 回复  |  直到 16 年前
        1
  •  0
  •   Samuel Tian    15 年前

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

    而不是你的经理。

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

    干杯

    推荐文章