how to bind part of a string in zk while using mvvm model

2k views Asked by At

So, let us say we want to do some things like this:

<label zclass="class1 class2 @load(vm.class)" />

How to do this in ZK?

the above code render zclass as class1 class2 @load(vm.class). But we want to execute @load?

2

There are 2 answers

0
Eugene Evdokimov On BEST ANSWER

You can use cat-like methods from the core taglib to concatenate strings. Something like this:

<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
...
<label zclass="@load(c:cat('class1 class2 ', vm.class))" />

For more details on core methods see here

0
TheBakker On

To do this, i went with an AbstractViewModel that contains all those "technical" methods i would like to use in my Zul.

Then i make every of my Viewmodel extends this abstractViewModel

public class AbstractTechnicalViewModel {

    /** @see java.text.MessageFormat#format(String, Object...) */
    public String format(final String pPattern, final Object... pParams) {
        return MessageFormat.format(pPattern, pParams);
    }

    /** @see org.apache.commons.lang.StringUtils#concatenate(Object[]) */
    public String concat(final Object... pParams) {
        return StringUtils.join(pParams);
    }
}

And then in my zul

tooltiptext="${vm.format(labels.my.label, param1)}"

Regards