cancel
Showing results for 
Search instead for 
Did you mean: 

Date InputField Set

Former Member
0 Kudos

Hi experts,

i've read a lot of threads in the forum but i've haven't found any answers to my question.

here is the code of my wdInit method in my StartView:

  public void wdDoInit()
  {
    //@@begin wdDoInit()
    String date_deb_init = new String("01/01/1900");
	String date_fin_inti = new String("31/12/9999");
	SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yyyy");
	
	try {
			wdContext.currentContextElement().setValDate_start(
				(java.sql.Date) sdf.parse(date_deb_init));

			wdContext.currentContextElement().setValDate_end(
				(java.sql.Date) sdf.parse(date_fin_inti));
	} catch (Exception e) {
		wdContext.currentContextElement().setAffichage(e.getMessage());
	}
    //@@end
  }

but, after execution, the 2 inputfields are still empty.

I don't under stand why it don't pass in the

try

block ...

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi,

use this code

java.util.Date tempDate = Calendar.getInstance().getTime();
		Date sqlDate = new Date(tempDate.getTime());

		wdContext.currentContextElement().setDate1(sqlDate);

where Date1 is the value attribute. This code will set the Date attribute with the current date.

Regards,

Gopi

Former Member
0 Kudos

ok but how i set the value "01/01/1900" to the date ?

luciano_leitedasilva
Contributor
0 Kudos

Hi,

Try this code:

Calendar date_1 = Calendar.getInstance();

date_1.set(Calendar.DAY_OF_MONTH, 1);

date_1.set(Calendar.MONTH, 0);

date_1.set(Calendar.YEAR, 1900);

wdContext.currentContextElement().setValDate(new Date(date_1.getTimeInMillis()));

Kind Regards,

Luciano

Former Member
0 Kudos

hi,

it doesn't work as SetValDate take java.sql.Date and date_1.getTimeInMillis() give a java.util.Date.

Then, i made a <i>cast</i> with :

wdContext.currentContextElement().setValDate_start((java.sql.Date) new Date(date_1.getTimeInMillis()));

and i got an error

java.lang.ClassCastException 

roberto_tagliento
Active Contributor
0 Kudos

java.sql.Date Today = new java.sql.Date(
Calendar.getInstance().get(Calendar.YEAR)-1900,
Calendar.getInstance().get(Calendar.MONTH),
Calendar.getInstance().get(Calendar.DAY_OF_MONTH) );
wdContext.currentContextElement().setValDate_start(Today);

Be sure that <b>ValDate_start</b> attribute is type Date and not java.util.Date

roberto_tagliento
Active Contributor
0 Kudos

Or

java.sql.Date Today = new java.sql.Date(System.currentTimeMillis());

or...

// Setup Calendar Object

Calendar Cal = Calendar.getInstance();

Cal.set(1998,12,4);

// Create java.sql.Date object

Today = new java.sql.Date(Cal.getTime().getTime());

Former Member
0 Kudos

What about

java.sql.Date.valueOf("1900-01-01")

Armin

Former Member
0 Kudos

hi,

thanks Armin,

it solvs my problem.

it looks so simple ...

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi ,

try this.

long time = System.currentTimeMillis();

java.sql.Date dt = new java.sql.Date(time);

wdContext.currentContextElement().setOne(dt);

Here one value attribute should be date .

Thanks,

Lohi.

Former Member
0 Kudos

hi,

Go thru this link

U might solve your problem.

Thanks,

Lohi.

Former Member
0 Kudos

hi,

i tray something like that but it change nothing.