2012-06-02 24 views
0

我對primefaces日曆組件有問題。 在託管bean的postconstruct方法中,我爲日曆組件設置了默認值。該默認值不會顯示在我的頁面中,並且顯示的字段爲空。初始化日曆日期的默認值

實現使用Mojarra 2.1.7-jboss和primefaces 3.2。

例如:

@ManagedBean(name = "dashboardController") 
@ViewScoped 
public class DashboardController implements Serializable { 

/** 
* selected date To 
*/ 
private Date selectedDateTo; 

@PostConstruct 
public void postconstruct() { 
     selectedDateTo = Calendar.getInstance().getTime(); 
} 

// getter setter 
+0

嘗試'selectedDateTo = new Date();'而不是... – Daniel

+0

它不起作用。 – ciavaldini

+0

然後顯示xhtml代碼 – Daniel

回答

2

嘗試:

@ManagedBean(name = "dashboardController") 
@ViewScoped 
public class DashboardController implements Serializable { 

/** 
* selected date To 
*/ 
private Date selectedDateTo = Calendar.getInstance().getTime(); 

/** 
* getter 
*/ 
public Date getSelectedDateTo() { 
    return selectedDateTo; 
} 

/** 
* setter 
*/ 
public void setSelectedDateTo(Date selectedDateTo) { 
    this.selectedDateTo = selectedDateTo; 
} 

除去PostConstruct方法,只是從日曆創建日期對象,如上所示。它對我來說工作得很好,顯示當前日期作爲日曆組件的默認日期。