I'm using a DateRangeItem and I need to get data out of it. I have coded a button for the user to click when the dates are set, however, I get exceptions when I try to get data out of the DateRangeItem and it's associated DateRange.
This piece of code always throws an exception - It seems to be whenever I'm trying to work with the DateRangeItem and DateRange objects.
Code:
// dateRangeItem and dateRange are declared as class level variables: private final DateRange dateRange; private final DateRangeItem dateRangeItem; // The working code follows: dateRangeItem = new DateRangeItem("dri",""); dateRangeItem.setWidth(180); dateRange = new DateRange(); dateRangeItem.setValue(dateRange); dateForm.setItems(dateRangeItem); vStack.addMember(dateForm); IButton goButton = new IButton(); goButton.setTitle("Go"); goButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { try { DateRange currentRange = dateRangeItem.getValue(); Date start = currentRange.getStartDate(); Date end = currentRange.getEndDate(); if (start != null && end != null) { pcdcListener.onDateRangeSelected("Both the dates are OK"); String range = String.valueOf(start.getMonth())+"/"+String.valueOf(start.getDay())+"/"+String.valueOf(start.getYear()); range += " to " + String.valueOf(end.getMonth())+"/"+String.valueOf(end.getDay())+"/"+String.valueOf(end.getYear()); } else { pcdcListener.onDateRangeSelected("One of the dates was null"); } } catch (Exception e){ pcdcListener.onDateRangeSelected("There was some sort exception"+e.getMessage()); } } });
Comment