Skip to Content
avatar image
Former Member

Trying to load dropdown box with dates

I'm trying to load a DropDownByIndex that is loaded by the following node:

Context

--PeriodDD

--- fromDate

--- toDate

--- value

(code}

Here is the code I was trying; but, it is not working! Here is the error I'm receiving:

The initial exception that caused the request to fail, was:

java.lang.ClassCastException: class java.util.Date:null incompatible with class java.sql.Date:null

at com.valero.kpivendorperformancereport.KpiVendorPerformanceReport.wdDoInit(KpiVendorPerformanceReport.java:189)

I have highlighted line 189 in green below.

{code]

// Load the Periods drop-down list

IPublicKpiVendorPerformanceReport.IPeriodDDElement periodElement = wdContext.nodePeriodDD().createPeriodDDElement();

Calendar calendar = Calendar.getInstance();

java.util.Date utilDate = new java.util.Date();

java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());

java.sql.Date quarterFrom = sqlDate; // just to initialize it.

java.sql.Date quarterTo = sqlDate; // just to initialize it.

int quarter = 0;

DateFormat dateOut = new SimpleDateFormat("MMM yyyy");

// Start with month of one year back from today

Date backDate = DateUtils.getBackDate(utilDate, 365);

calendar.setTime(backDate);

// Populate the 12 months between

for (int i = 0; i < 12; i++)

{

calendar.set(calendar.HOUR_OF_DAY, 0);

calendar.set(calendar.MINUTE, 0);

calendar.set(calendar.SECOND, 0);

calendar.set(calendar.MILLISECOND, 0);

calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), 1);

{color:green} sqlDate = (java.sql.Date) DateUtils.getSqlDate(calendar.getTime());

// If this is the beginning of a 3-month period

if (i == 0 || i == 3 || i == 6 || i == 9)

{

quarterFrom = sqlDate;

quarter++;

}

periodElement.setFromDate(sqlDate);

periodElement.setToDate(DateUtils.getLastDayOfMonth(calendar, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)));

periodElement.setValue(dateOut.format(calendar.getTimeInMillis()));

// If this is the end of a 3-month period

if (i == 2 || i == 5 || i == 8 || i == 11)

{

quarterTo = sqlDate;

periodElement.setFromDate(quarterFrom);

periodElement.setToDate(quarterTo);

periodElement.setValue("Quarter " + quarter);

}

calendar.add(Calendar.DATE, 1);

}

{code]

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Mar 19, 2010 at 05:15 PM

    Hi Ronald,

    Everything seem to be fine to me.

    >>Check the imports java.util.Date adn remove it from imports in your code in controller or view.

    Import java.sql.Date in you code. By organizing import (ctrlshiftO) the select Date for "java.sql.Date"

    Then try to execute. I will work

    Hope it helps

    Regards

    Arun

    Add comment
    10|10000 characters needed characters exceeded