0

Validator not firing for Grid?

asked 2012-08-19 07:29:39 +0800

davout gravatar image davout
1435 3 18

I have set a validator against a grid, like:

<grid
	model="@load(vm.childConstraintAllocationModel) 
                @save(vm.childConstraintAllocationModel,before='constraintNext') 
                @validator(vm.childConstraintValidator)">


... but the validator is not being called. Is this a bug?

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2012-08-19 17:19:57 +0800

mkommer gravatar image mkommer
111

updated 2012-08-19 17:21:39 +0800

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....

link publish delete flag offensive edit

answered 2012-08-19 18:57:50 +0800

davout gravatar image davout
1435 3 18

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>

link publish delete flag offensive edit

answered 2012-08-19 18:58:23 +0800

davout gravatar image davout
1435 3 18

Fo my own situation I get no error, or any output to suggest that the validator is being triggered

link publish delete flag offensive edit

answered 2012-08-19 19:50:29 +0800

mkommer gravatar image mkommer
111

updated 2012-08-19 21:40:53 +0800

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.

link publish delete flag offensive edit

answered 2012-08-20 00:23:52 +0800

mkommer gravatar image mkommer
111

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>

link publish delete flag offensive edit

answered 2012-08-20 00:28:41 +0800

mkommer gravatar image mkommer
111

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" />						    

link publish delete flag offensive edit

answered 2012-08-20 00:46:27 +0800

samchuang gravatar image samchuang
4084 4

hi @davout

have you solve the issue ? if not, you may need to post a runnable sample code, so others can debug it

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-08-19 07:29:39 +0800

Seen: 109 times

Last updated: Aug 20 '12

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