0

Stop further execution after messagebox.show()

asked 2014-02-20 07:27:38 +0800

nsharma gravatar image nsharma flag of India
917 1 11

updated 2014-02-20 07:29:16 +0800

I came across a scenerio in my project:

Zul code:

<textbox onChange="@command('changeValue')"/>

<button onClick="@command('saveData')"/>

ViewModel code:

    @command
    public void changeValue(){
...some validation fails...
    Messagebox.show("show some error on data change");
    }

    @command
    public void saveData(){
...some validation fails...
    Messagebox.show("some error in save");
    .
    .
    ....<some code>
    }

Now when i change the value in text box and directly click on save button,Both the event get fired : first, onChange and then onClick of button.

Due to this both the error messages are shown.

I want that when first messagebox is shown ,the execution should stop and should allow only the first messagebox .

Thanxx in advance.

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-02-20 08:45:41 +0800

chillworld gravatar image chillworld flag of Belgium
5337 4 9
https://github.com/chillw...

updated 2014-02-20 08:46:49 +0800

No bug but bad practice of MVVM

do this (the extra label is just for you to see when things happens) :

zul :

<textbox value="@load(vm.textBoxValue) @save(vm.textBoxValue, before='saveData')"/>
<label value="@bind(vm.textBoxValue)" />
<button onClick="@command('saveData')" label="change"/>

VM :

private String textBoxValue;

@Command
public void saveData () {
    Messagebox.show("saveData " + textBoxValue);
}

public String getTextBoxValue() {
    return textBoxValue;
}

public void setTextBoxValue(String textBoxValue) throws WrongValueException  {
    System.out.println(textBoxValue);
    if (textBoxValue.equalsIgnoreCase("chillworld")) {
        throw new WrongValueException("chillworld not permitted");
    }
    this.textBoxValue = textBoxValue;
}

Greetz chill.

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-02-20 07:27:38 +0800

Seen: 32 times

Last updated: Feb 20 '14

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