Question

I am checking for a change in value of a date. The ValueChangeHandler is recognising a date (e.g. 1/5/2014 is updated to the DB when entered). However, when I delete a date it is not recognised (i.e., the DB is not updated to null - I have tried Backspace, highlight and Del, overtyping with spaces). I then entered a new date (2/5/2014) and this was updated to the DB. Any ideas as to why this code does not recognise that I have removed the date please.

Regards,

Glyn

I have updated this with the code suggested by Braj. Unfortunately this did not work.

final DateBox awardedDate = new DateBox();
awardedDate.setFormat(new DefaultFormat(DateTimeFormat.getFormat("dd/MM/yyyy")));
awardedDate.setValue(ymAwards.getCaAwardedDate());
awardedDate.setWidth("75px");

//Add change handler for the awarded date.
//Only a Leader or Administrator can update the date
if (accountLevel.equals("Leader") || accountLevel.equals("Administrator")) {
    awardedDate.addValueChangeHandler(new ValueChangeHandler<java.util.Date>() {
        int pog = 0;
        public void onValueChange(ValueChangeEvent<java.util.Date> event) {
            if (pog == 0) {
                pog++;
                Window.alert("First change hadler.");

                //Check for a null date and handle it for dateBoxArchived and dateBoxPackOut
                java.sql.Date sqlDateAwarded = awardedDate.getValue() == null ? null : new java.sql.Date(awardedDate.getValue().getTime());
                AsyncCallback<YMAwards> callback = new YMAwardedDateHandler<YMAwards>();
                rpc.updateYMAwarded(youthMemberID, returnAwID, sqlDateAwarded, callback);
            }else{
                pog = 0;
            }
        }
    });
    awardedDate.getTextBox().addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            if (event.getValue() == null) {
                Window.alert("Second change hadler.");
                //Check for a null date and handle it for dateBoxArchived and dateBoxPackOut
                java.sql.Date sqlDateAwarded = awardedDate.getValue() == null ? null : new java.sql.Date(awardedDate.getValue().getTime());
                AsyncCallback<YMAwards> callback = new YMAwardedDateHandler<YMAwards>();
                rpc.updateYMAwarded(youthMemberID, returnAwID, sqlDateAwarded, callback);
            }
        }
    });
}
Was it helpful?

Solution

Add this line:

awardDate.setFireNullValues(true);

This was added in GWT 2.5.

OTHER TIPS

Try this one also

    final DateBox dateBox = new DateBox();

    dateBox.getTextBox().addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            if (dateBox.getValue() == null) {
                System.out.println("date value is empty");
                // your code here
            }
        }
    });

output:

date value is empty

DateBox#addValueChangeHandler() fires when there is any change in date via date picker.

You can check the value in text box using TextBox#addValueChangeHandler().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top