0

DateBox not refresh binded value after @NotifyChange

asked 2014-03-10 15:49:13 +0800

pasqualeleone gravatar image pasqualeleone flag of Italy
81 2

updated 2014-03-10 15:53:35 +0800

hi guys, this is a section of code that causes me problems.

zul file

<button id="btnPrevMonth"
                            image="/image/common/prev.png"
                            tooltiptext="${labels.prjSys.timecard.button.prevmont}"
                            onClick="@command('monthPrev')"
                            disabled="@load(not objVM.isEmployeeSelected)"/>
                        <datebox id="dteMonth" 
                            width="80px"
                            disabled="@load(not objVM.isEmployeeSelected)"
                            format="${labels.dateMMMyyyyFormat}"
                            value="@bind(objVM.selectedMonthYear)"
                            />

java file

    @Command("monthPrev")
@NotifyChange("selectedMonthYear")
public void monthPrev(){
    if(selectedMonthYear != null){
        Calendar tmp = Calendar.getInstance();
        tmp.setTime(selectedMonthYear);
        tmp.add(Calendar.MONTH, -1);
        this.selectedMonthYear.setTime(tmp.getTimeInMillis());
    }
}

As you can see the value of datebox that has a bind on the Date object selectedMonthYear is not updated, although there is the @NotifyChange. I wonder if this is a bug or I'm wrong some instruction.

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-03-11 01:42:38 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

The Date object was caught by Datebox as it's value member field, since you change Date object's inside TimeInMillis directly, when binder set the value back, Datebox checked it's the same object and didn't update it to client. change you code from selectedMonthYear.setTime(tmp.getTimeInMillis()); to selectedMonthYear = tmp.getTime(); could avoid this.

link publish delete flag offensive edit

Comments

Ok, work! This is the solution that i was looking! Thank You!

pasqualeleone ( 2014-03-11 15:30:48 +0800 )edit
1

answered 2014-03-11 04:56:21 +0800

sitansu gravatar image sitansu
2254 13
http://java91.blogspot.in...

Just Try it :

@Command("monthPrev")
@NotifyChange("selectedMonthYear")
public void monthPrev(){
    if(selectedMonthYear != null){
        Calendar tmp = Calendar.getInstance();
        tmp.setTime(selectedMonthYear);
        tmp.add(Calendar.MONTH, -1);
        this.selectedMonthYear.setTime(tmp.getTimeInMillis());

     BindUtils.postNotifyChange(null, null, VM.this, "selectedMonthYear");
    }
}
link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2014-03-10 15:49:13 +0800

Seen: 26 times

Last updated: Mar 11 '14

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More