jsf - How to store created date on clicking submit button -


how can created date , store database when click command button.

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

in bean have

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

how can created date using backing bean when try print on console show null suggetions?

your date object null because never initialized. need do:

date createddate = new date(); 

this gives createddate actual date created value.


on small tangent, suggest using calendar when dealing dates. partly because date api flawed , deprecated.

calendar singleton object can used following:

calendar createddate = calendar.getinstance(); 

when creating object use current locale , timezone, unless specify otherwise.

hope helps!


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -