0

MVVM : validator / include / multiple zul

asked 2012-10-22 09:07:57 +0800

mkommer gravatar image mkommer
111

Hi,

we have a page which include dynamic choice of zul (depends about a combobox which set the src of the include).
We would like to call a validator before a command.
We tried with a globalcommand but it's not working.

Here our code :

Main.zul

<groupbox>
    <include id="specific" src="@load(vm.specific)"/>
</groupbox>

<button label="${labels.action.generate" onClick="@global-command('generate'"/>

Main.java (first VM)

@GlobalCommand("generate")
public void generate() {
...
}

Test.zul (second zul which is used into the include)

<textbox value="@load(vm.mytest) @save(vm.mytest, before='generate') @validator(test.validator.NotEmptyValidator)" />

the validator is never called when we click on the generate button.

Any idea ?

Thank you

delete flag offensive retag edit

12 Replies

Sort by ยป oldest newest

answered 2012-10-22 10:17:19 +0800

Steva77 gravatar image Steva77 flag of Italy
1014 3
http://www.research.softe...

Take care!
You are missing several closing brackets, e.g. a ) in

onClick="@global-command('generate'"/>
.
BTW, which is the code of your test.validator.NotEmptyValidator class?

link publish delete flag offensive edit

answered 2012-10-22 12:49:54 +0800

mkommer gravatar image mkommer
111

Yeah my mistake. The code is not on this computer, so i couldn't copy/paste.
The NotEmptyValidator extends the AbstractValidator, and override the validate method, exactly as advise by Zk :p

I think the pb is the scope : main.zul / test.zul which is included. It seems the before='generate' is not apply....
But how to solve that ? :(
GlobalCommand is done for that, isn't it ?

link publish delete flag offensive edit

answered 2012-10-22 13:44:26 +0800

Steva77 gravatar image Steva77 flag of Italy
1014 3
http://www.research.softe...

I am (still ;) not that expert on ZK6... GlobalCommand work to notify events to e.g. others composers/view models.
What you want is generate some text with the button and validate it on the other page?
It depends when the validator is invoked, since you are binding the textbox....

link publish delete flag offensive edit

answered 2012-10-22 14:39:01 +0800

mkommer gravatar image mkommer
111

updated 2012-10-22 14:42:38 +0800

Here the real zul code :

Main.zul

<?page title="SIA - Main Page" contentType="text/html;charset=UTF-8"?>
<?meta http-equiv="X-UA-Compatible" content="IE=7" ?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<zk>
<window id="wMain" border="none" apply="org.zkoss.bind.BindComposer"
 viewModel="@id('vm') @init(mainVm)"
 validationMessages="@id('vmsgs')">
 
 <!-- Header -->
 <include id="incHeader" src="/pages/template/header.zul" ></include>

 <!-- Menubar -->
 <include id="incMenu" src="/pages/template/menu.zul" ></include>
 
 <!-- Div de centrage  -->
 <div sclass="contentCenter">
... 
                <separator></separator>
                <groupbox mold="default" >
                        <include id="iSpecificPart" src="@load(vm.specificPart)" ></include>
                </groupbox>
                <separator></separator>
 
  <div id="divButtonsBottom" align="center" style="margin:10px;">
                        <button id="btnGenerate"
                                disabled="@bind(vm.disableGenerationButton eq true)"
                                label="${labels.action.generate}"
                                onClick="@global-command('generateDu')"
                                image="/images/icons/icon_save.png" ></button>
                        <checkbox id="chbxReco" 
                                label="${labels.label.recomposition}"
                                disabled="@bind(vm.disableChbxReco eq true)"
                                style="margin-top:50px"></checkbox>
  </div>
  </div>
 
 <!-- Footer -->
 <include id="incFooter" src="/pages/template/footer.zul" ></include>
        
</window>
</zk>

And the include :

Elm.zul

<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<?meta http-equiv="X-UA-Compatible" content="IE=7" ?>
<zk>
<window border="none" apply="org.zkoss.bind.BindComposer"
 viewModel="@id('vms') @init(elmgaVm)"
 validationMessages="@id('vmsgs')">
    <div align="center">
        <hbox width="500px">
        <!--
            Zone de saisie de la date et de la version Aircraft
        -->
        <groupbox width="275px">
            <tablelayout columns="2">
                <tablechildren width="150px">
                    <label value="${labels.label.elm.revisionDate}" ></label>
                </tablechildren>
                <tablechildren>
                    <datebox id="dbRevisionDate" 
                             format="dd/MM/yyyy" hflex="1"
                             value="@bind(vms.revisionDate)"></datebox>
                </tablechildren>
                <tablechildren>
                    <label value="${labels.label.elm.version}" ></label>
                </tablechildren>
                <tablechildren>
                    <textbox id="aircraftText" value="@load(vms.aircraftVersion)
                    @save(vms.aircraftVersion, before='generateDu') @validator(notEmptyValidator)" ></textbox>
                </tablechildren>
                <tablechildren>
                    <label value="@bind(vmsgs)" visible="@bind(vms.showMessage)" sclass="red"></label>
                </tablechildren>
            </tablelayout>
        </groupbox>
    </div>
</window>
</zk>

We want to click on the btnGenerate in Main.zul

                        <button id="btnGenerate"
                                disabled="@bind(vm.disableGenerationButton eq true)"
                                label="${labels.action.generate}"
                                onClick="@global-command('generateDu')"
                                image="/images/icons/icon_save.png" ></button>

and have the validator on textbox of Elm.zul be activated before the command :

                    
<textbox id="aircraftText" value="@load(vm.aircraftVersion)
                    @save(vm.aircraftVersion, before='generateDu') @validator(notEmptyValidator)" ></textbox>

In others words, have a validator in included zul activated by a command on main zul.

We would like to validate the textbox when the user click on the button, and not on a onchanging event cause the user could click directly on the button without editing the textbox.

link publish delete flag offensive edit

answered 2012-10-22 15:35:49 +0800

Steva77 gravatar image Steva77 flag of Italy
1014 3
http://www.research.softe...

I see... a word from tech guys might help here, it could be an issue on the chain of invocations...

link publish delete flag offensive edit

answered 2012-10-23 06:21:28 +0800

samchuang gravatar image samchuang
4084 4

updated 2012-10-23 06:22:53 +0800

hi, it looks like a bug to me, but it may also be ZK's spec, I am not sure

http://tracker.zkoss.org/browse/ZK-1423

link publish delete flag offensive edit

answered 2012-10-23 06:35:41 +0800

samchuang gravatar image samchuang
4084 4

updated 2012-10-23 07:12:30 +0800

after read doc again, that's ZK's spec

1.
refer to Phases of Command Execution
2.
refer to globe command execution

Note that the globe command doesn't have "validation", "save", etc..

The globe command is used for inter-viewmodel communication, a view model fire globe command to another view model, it shall not change other's view model's status

link publish delete flag offensive edit

answered 2012-10-23 07:53:09 +0800

Steva77 gravatar image Steva77 flag of Italy
1014 3
http://www.research.softe...

Great, thanks samchuang!

link publish delete flag offensive edit

answered 2012-10-23 09:40:22 +0800

mkommer gravatar image mkommer
111

Thank you SamChuang.

Too bad, this is somehow a limitation of validators.
So, if we want to continue to use them, we have to trigger them manually.
Is it possible ? or should we have to change our validators into a normal class (and not extends AbstractValidator) ?

link publish delete flag offensive edit

answered 2012-10-23 14:03:46 +0800

mkommer gravatar image mkommer
111

The pb is the same with 1 unique zul, but multiple viewmodel....

strange :(

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2012-10-22 09:07:57 +0800

Seen: 418 times

Last updated: Oct 24 '12

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