-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have to do trim on @bind('vm.state.email') . How to do trim in @bind?
Oke, let's start to apologise for the short comment.
I looked at this on the phone, didn't have the time or resources to answer this correct so I pointed already to a possible solution.
Well, @bind
is a shortcut for @load
and @save
together.
While @load
just calls a getter, it's possible to do : @load('vm.state.email.trim()')
Look carefully at the trim()
, yes the ()
is needed because otherwise he will call getTrim()
.
But @save()
calls setters, trim function isn't a setter method, it doesn't take any parameters in, so that's the reason why it never can be done in this way.
You can add the trim method in your getter and setter method before returning/setting your variable.
If it's a basic business requirement of email, that's the place where you need to do it.
Like this, every usage of email will be correct through your whole application.
Solution 2 : Converter.
Zul :
="@bind('vm.state.email') @converter(vm.trimConverter)">
Java :
public class MyViewModel{
private Converter trimConverter = new Converter() {
// Implements the 2 methods and do your stuff.
// Example in link provided.
};
public Converter getTrimConverter(){
return myConverter;
}
}
Custom components are underrated in ZK.
They are powerfull, easy to use and the advantage is refactoring is in 1 place in stead of multiple places.
But a custom components only pays off when you will actually use it more then once.
In this case, you can make a class who extends your component (I guess Textbox).
Override the getter (and/or setter) methods for value and add the trim()
to it.
Very easy and your zul can stay clean that way.
So, depending on your needs, you have 3 possible solutions now.
Chill.
Asked: 2018-03-16 17:45:19 +0800
Seen: 12 times
Last updated: Mar 18 '18
Use a convertor.
chillworld ( 2018-03-17 02:23:02 +0800 )edit@chillworld Thank You!:)
answer1 ( 2018-03-19 13:34:03 +0800 )edit