-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have set a validator against a grid, like:
<grid model="@load(vm.childConstraintAllocationModel) @save(vm.childConstraintAllocationModel,before='constraintNext') @validator(vm.childConstraintValidator)">
Hello,
what is your problem exactly ?
Do you have an exception generated ?
For my part, i tried to set a validator on a field exactly as i seen in the smalltalk about "MVVM - Spring - JPA architecture", and i have an exception "result of expression '${identifierSearchValidator}' is not a Validator, is null".
Here my code :
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?> <zk> <window border="none" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init(referencesListVm)" validationMessages="@id('vmsgs')"> <textbox id="tbIdent" width="150px" value="@load(vm.identifier) @save(vm.identifier, before='search') @validator(identifierSearchValidator)" errorMessage="@load(vmsgs[\ident\])" ></textbox> </window> </zk>
In my MVVM, i have a property "private String identifier = """ with its getter & setter.
And finally, i have a class managed by spring :
@Component("identifierSearchValidator") public class IdentifierSearchValidator extends AbstractValidator { @Override public void validate(ValidationContext ctx) { String identifier = (String)ctx.getProperty().getValue(); if (!identifier.trim().matches("[%a-zA-Z0-9]")) { //addInvalidMessage(ctx, "ident", Labels.getLabel("test.validator.identifier.notmatch")); addInvalidMessage(ctx, "ident"); } } }
I thank in advance any kind soul who might help me....
I think you are missing the VM prefix on the validator parameter, like:
<textbox id="tbIdent"
width="150px"
value="@load(vm.identifier) @save(vm.identifier, before='search') @validator(vm.identifierSearchValidator)"
errorMessage="@load(vmsgs[\ident\])" ></textbox>
Are you sure you can declare the validator directly on the grid without declare a form ?
Did you try to declare your validator directly on the field that you want to control ?
[\edit\] i miss the VM prefix volontary cause i have a spring bean (validator). That is working perfectly for the ViewModel. But i will try as soon as possible anyway :p
It seems i have the same pb with a Converter. I follow exactly the code from the smalltalk. They didn't use VM prefix and call directly their bean.
For my case, my mistake...i forget to add a new base package to scan for annoted spring bean :p
Anyway, for your case, this is what i do for a grid :
<style> .z-label.red{ color:red; } </style> ... <grid form="@id('fx') @load(vm.user) @save(vm.user,after='save') @validator('userValidator')"> <textbox value="@bind(fx.firstName)"/> <label value="@load(vmsgs[firstName'])" sclass="red"/> </grid>
Or directly on the field :
<label value="${labels.dbref.label.ident}" /> <textbox id="tbIdent" width="150px" value="@load(vm.identifier) @save(vm.identifier, before='search') @validator(identifierSearchValidator)" /> <label value="@bind(vmsgs)" sclass="red" />
Asked: 2012-08-19 07:29:39 +0800
Seen: 109 times
Last updated: Aug 20 '12