0

Input validation

asked 2013-06-24 12:53:05 +0800

santoshkarna gravatar image santoshkarna
13 2

I want to create textbox which will take only text.Below is my validator method and zul page.i am using ZK 6.5.0 and i learned this from tutorial

MVVM in ZK 6 - Design CRUD page by MVVM pattern

Author

    Dennis Chen, Senior Engineer, Potix Corporation 
Date

    November 14, 2011 

Version

    ZK 6 FL-2012-01-11 and after

Below is my zul and validator method.

zul page

 <window title="Pet Store" border="normal"
apply="org.zkoss.bind.BindComposer" viewModel="@id('vm')      @init('com.petlist.santosh.vm.PetListVM')"    validationMessages="@id('vmsgs')">

 <row>Name <textbox id="nbox" value="@bind(vm.selected.name) @validator(vm.textValidator)" />
                <label value="@load(vmsgs[nbox])"/>
                </row>    //this is not working

                <row>Owner <textbox value="@bind(vm.selected.owner)" constraint="/^[a-zA-Z\ \']+$/: Please enter text only"/></row>  //this is working fine

</window>

validator method

public Validator getTextValidator(){ return new AbstractValidator() {

        public void validate(ValidationContext ctx) {
            String str = (String)ctx.getProperty().getValue();
            String reg="^[a-zA-Z\\']+$";
            boolean mes=str.matches(reg);
            System.out.println("the msg:"+mes);//upto this line working
            if(mes==false){
                addInvalidMessage(ctx, "text only ");//but this method doesn't work
            }

        }
    };

}

looking for appropriate solution.

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-06-25 13:19:10 +0800

santoshkarna gravatar image santoshkarna
13 2

updated 2013-07-03 07:54:26 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

My problem is solved.I was getting problem due to wrong UI design.I corrected this part.

<row>
    <hbox>Name</hbox>
    <vbox>
        <textbox id="nbox" value="@bind(fx.name)  @validator(vm.textValidator)" />
        <label value="@load(vmsgs[nbox])" style="color: red;"/>
    </vbox>
</row
link publish delete flag offensive edit
Your answer
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
2 followers

RSS

Stats

Asked: 2013-06-24 12:53:05 +0800

Seen: 240 times

Last updated: Jul 03 '13

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