-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
Take care!
You are missing several closing brackets, e.g. a ) in
onClick="@global-command('generate'"/>
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 ?
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....
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.
I see... a word from tech guys might help here, it could be an issue on the chain of invocations...
hi, it looks like a bug to me, but it may also be ZK's spec, I am not sure
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
Great, thanks samchuang!
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) ?
Asked: 2012-10-22 09:07:57 +0800
Seen: 418 times
Last updated: Oct 24 '12