如何在JSF的网页上显示系统日期?

时间:2014-01-16 14:13:27

标签: java jsf jsf-2

我想在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
}

1 个答案:

答案 0 :(得分:0)

例如:

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