当我单击命令按钮时,如何获取创建日期并将其存储到数据库。
<p:inputText id="diff" styleClass="daysNumber" value="#{dayDiffBean.diff}">
<f:valueChangeListener value="#{vacatioBean.vacation.balanceDay}" />
</p:inputText>
<h:commandButton styleClass="sndbutton1" value="#{text['employee.send']}"
action="#{vacationBean.addVac}" />
在Bean中我有
private static final long serialVersionUID = 1L;
private Date vEndDate;
private Date vStartDate;
private Date createdDate;
private String isNobody;
Requestrelax vacation;
Employee e;
private short balanceDay;
@EJB
VacationLocal vacations;
@ManagedProperty(value="#{loginBean.userId}")
Integer userId;
@EJB
EmployeesLocal employees;
@PostConstruct
public void init(){
System.out.println("0");
vacation=new Requestrelax();
e=employees.getEmployee(userId);
vacation.setEmployee(e);
}
public void addVac(){
System.out.println("1");
System.out.println("____________" +createdDate);
vacation.setCreatedDate(createdDate);
vacations.addEmployeeVacation(vacation);
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public Employee getE() {
return e;
}
public void setE(Employee e) {
this.e = e;
}
public Requestrelax getVacation() {
return vacation;
}
public void setVacation(Requestrelax vacation) {
this.vacation = vacation;
}
public Date getvEndDate() {
return vEndDate;
}
public void setvEndDate(Date vEndDate) {
this.vEndDate = vEndDate;
}
public Date getvStartDate() {
return vStartDate;
}
public void setvStartDate(Date vStartDate) {
this.vStartDate = vStartDate;
}
public short getBalanceDay() {
return balanceDay;
}
public void setBalanceDay(short balanceDay) {
this.balanceDay = balanceDay;
}
public Date getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
}
当我尝试在控制台上打印它时,如何使用支持bean获取创建日期,它显示为null 任何建议?
答案 0 :(得分:2)
除了Josef E。的答案之外,我还建议使用Joda Time,因为Java Date API在以前版本的Java中是如何的。
幸运的是,在Java 8中,这个问题已得到解决。
答案 1 :(得分:0)