2010-11-11 73 views
0

標記:奇怪的行爲

<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屬性,否則不會發生這種情況。

+0

這是如何[java] **和** [c] **和** [.net]? – 2010-11-11 13:25:25

+0

這是Java(JSF 2.0) – siva636 2010-11-11 13:51:25

+0

但您將C和NET添加到標籤。在這個問題中他們沒有任何意義,所以Marc刪除了它們(並且我用JSF標籤替換了JSP標籤,因爲根本不使用JSP,而是Facelets) – BalusC 2010-11-11 13:53:46

回答

0

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

,而不是你ManagedBean。

至少這解決了我的問題。讓我知道你是否知道原因。

歡呼聲