簡體   English   中英

如何在JSF中的網頁上顯示系統日期?

[英]How to display system date on the webpage in JSF?

我想在jsf頁面中顯示當前的語言環境系統日期。 我有以下代碼,但無法正常工作。

<p:column styleClass="columnA">SOP Date</p:column>
<p:column styleClass="columnB">
    <h:outputText value="#{bean.currentDate}" />
</p:column>

托管bean看起來像代碼:

@ManagedBean(name = "bean")
public class SopDate implements Serializable {

    public String currentDate;

    @PostConstruct
    public void init(){
       SopCurrentDate();
    }

    public void SopCurrentDate(){
        DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
        Calendar cal = Calendar.getInstance();
        this.currentDate = df.format(cal.getTime());
      }
      // getter and setter
}

例如:

<h:outputText value="#{bean.currentDate}">
   <f:convertDateTime type="date" pattern="#{bean.format}" timeZone="(here your timezone)"/>
 </h:outputText>

豆角,扁豆:

@ManagedBean(name = "bean")
@ViewScoped
public class SopDate implements Serializable {

    public Date currentDate;
    public String format;  

    @PostConstruct
    public void init(){
       SopCurrentDate();
    }

    public void SopCurrentDate(){
       currentDate = new Date(); 
       format = "dd-MM-yyyy";
    }
      // getter and setter
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM