answered
2018-02-28 02:19:07 +0800
psinalberth 52 ● 6 Thanks! It worked! Now, could you tell me what am I doing wrong? I'm testing formBeanValidator
using ZKEval archetype, the validation is working but even if I fill some property, the validation message is still appearing.
<div class="section" viewModel="@id('vm') @init('br.ps.teste.viewmodel.PersonViewModel')" validationMessages="@id('vmsgs')">
<button sclass="button is-info" label="Save" onClick="@command('save')" />
<div class="container" form="@id('fx') @load(vm.person) @save(vm.person, after='save') @validator('formBeanValidator', prefix='p_')">
<div class="column is-8 is-offset-2">
<div class="field">
<label sclass="label" value="Name" />
<div class="control">
<textbox sclass="@load(not empty vmsgs['p_name'] ? 'input is-danger': 'input')" value="@bind(fx.name)"/>
<label sclass="help is-danger" value="@load(vmsgs['p_name'])" />
</div>
</div>
</div>
<div class="column is-8 is-offset-2">
<div class="field">
<label sclass="label" value="Address" />
<div class="control">
<textbox sclass="@load(not empty vmsgs['p_address'] ? 'input is-danger': 'input')" value="@bind(fx.address)"/>
<label sclass="help is-danger" value="@load(vmsgs['p_address'])" />
</div>
</div>
</div>
<div class="column is-8 is-offset-2">
<div class="columns">
<div class="column is-6">
<div class="field">
<label sclass="label" value="Age" />
<div class="control">
<intbox sclass="@load(not empty vmsgs['p_age'] ? 'input is-danger': 'input')" value="@bind(fx.age)" />
<label sclass="help is-danger" value="@load(vmsgs['p_age'])" />
</div>
</div>
</div>
<div class="column is-6">
<div class="field">
<label sclass="label" value="Weight" />
<div class="control">
<decimalbox sclass="@load(not empty vmsgs['p_weight'] ? 'input is-danger': 'input')" value="@bind(fx.weight)" />
<label sclass="help is-danger" value="@load(vmsgs['p_weight'])" />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
I took the markup from MVVM Book
<window id="win" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init(foo.MyViewModel)"
validationMessages="@id('vmsgs')">
<grid width="600px" form="@id('fx') @load(vm.user) @save(vm.user, after='save')
@validator('formBeanValidator', prefix='p_')">
<textbox value="@bind(fx.firstName)"/>
<label value="@load(vmsgs['p_firstName'])"/>
</grid>
<!--more components-->
</window>
It looks like the object going to validation is always null. I have a button which is intented to invoke a method to create a new instance of Person
, so I click it and the object is created. Even when I don't, the validation process is invoked.
The wrongvalueexception constructor has place for a component. If you provide the component, message will be shown there.
chillworld ( 2018-02-27 03:05:48 +0800 )editThanks @chillworld for replying me. It turns that I don't have a component. I'm using MVVM and in my ViewModel there is only a
psinalberth ( 2018-02-27 03:46:04 +0800 )editperson
object, so there is no references to any view element. I'd need something like vmsgs approach with a validator like 'formBeanValidator', but it is not available.