0

Binding problem after datebox modified by onChange event

asked 2013-09-06 16:02:58 +0800

yohann gravatar image yohann
57

updated 2013-09-09 06:33:25 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Hi all,

I have a problem with databinding if I modify the value of a dateBox on an onChangeEvent :

zul file :

<textbox onChange="@command('onAgeChange', age=event.value, dob=dtbxDOB)"/>
<datebox id="dtbxDOB" value="@bind(fx.dob)" />

VM :

@Command
@NotifyChange("dob")
public void onAgeChange( @BindingParam("age") String    strAge_P
            ,@BindingParam("dob") Datebox   dtbxDOB_P){

Calendar cal = Calendar.getInstance();
Integer iCurrentYear = cal.get(Calendar.YEAR);
Integer iAge = Integer.valueOf(strAge_P);
Integer iDOBYear = iCurrentYear - iAge;
Calendar calDOB = Calendar.getInstance();
calDOB.set(Calendar.YEAR, iDOBYear);
calDOB.set(Calendar.DAY_OF_MONTH, 1);
calDOB.set(Calendar.MONTH, 0);
dtbxDOB_P.setValue(calDOB.getTime());
}

The purpose is to set the date if the user enter the age, but the problem is that the modified date is not bound. Is anyone has an idea please ?

Sorry for my english. Many Thanks !

delete flag offensive retag edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2013-09-06 19:42:22 +0800

roliroli gravatar image roliroli
164 4

updated 2013-09-09 06:33:52 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Hello,

there is just a little mistyping...

<textbox onchange="@command('onAgeChange', age=event.value, dob=dtbxDOB)"/>

"onchange" should be "onChange"

A suggestion is:

Don't need to pass datebox as parameter when you're using @bind with datebox. It will update automatically when you change "dob" because you have @NotifyChange

In design concept, ViewModel is independent to UI Component.

link publish delete flag offensive edit
0

answered 2013-09-10 15:25:49 +0800

yohann gravatar image yohann
57

Hello,

Thanks for your response, but in my question there is no "onchange" in my zul file but "onChange". In fact, i need to set the datebox's value with the textbox's input representing the age (old?) of the user. In example if the user set "20" in the textbox, the value of the date box is automatically set with 01/01/1993. This is working well with the onChange event but after the form cannot be validated because the Dob is mandatory.

Very sorry for my english and many thanks for your help !

link publish delete flag offensive edit
0

answered 2013-09-23 03:27:51 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

updated 2013-09-23 03:28:42 +0800

Hi yohann,

You can pass fx variable to the command

<textbox onChange="@command('onAgeChange', age=self.value, fx=fx)"/>

the call notify change in your command

@Command
public void onAgeChange( @BindingParam("age") String strAge_P, @BindingParam("fx") Form fx) {

    BindUtils.postNotifyChange(null, null, fx, "dob");
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: 2013-09-06 16:02:58 +0800

Seen: 104 times

Last updated: Sep 23 '13

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