-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
is there any way to do :
label="@{bean.firstName} {bean.lastName}" ???
I want label to show firstname + lastname . (I don't want to use EL. only databinding)
I know only the way to concenate single labels:
<hbox pack="start" width="100%"> <label value="@{bean.firstName}" /> <label value="@{bean.lastName}" /> </hbox>
best
Stephan
I think you could also do it with getters/setters like this:
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?> <zk> <zscript> import org.zkoss.zk.ui.util.GenericForwardComposer; public class Bandmate { private String first; private String last; public Bandmate(String f, String l) { setFirst(f); setLast(l); } public String getFirst() { return first; } public void setFirst(String f) { first = f; } public String getLast() { return last; } public void setLast(String l) { last = l; } public void setFullName(String fn) { // do nothing } public String getFullName() { return first + " " + last; } } List Bandmates = new ArrayList(); Bandmates.add(new Bandmate("David", "Gilmore")); Bandmates.add(new Bandmate("Roger", "Waters")); Bandmates.add(new Bandmate("Nick", "Mason")); Bandmates.add(new Bandmate("Richard", "Wright")); Bandmates.add(new Bandmate("Syd", "Barrett")); </zscript> <window id="main" style="padding: 25px;"> <grid id="myGrid" fixedLayout="true" model="@{Bandmates}"> <columns> <column label="First"/> <column label="Last"/> <column label="Full Name"/> </columns> <rows> <row self="@{each=Bandmate}"> <cell><label value="@{Bandmate.first}" /></cell> <cell><label value="@{Bandmate.last}" /></cell> <cell><label value="@{Bandmate.fullName}" /></cell> </row> </rows> </grid> </window> </zk>
Stephan, please tell me if I'm wrong here. :)
Todd
Hi,
unlike EL's there are no expressions in databinding.
Extend you servicelayer/bean - is the easiest way (like todd's) example.
Sometimes you could solve this via UI (like stephan's example).
However, if you don't want extend your bean/service-layer you have some options:
1.) use TypeConverters (check docs, my examples )
2.) create your own/extended bean i.e. BandmateUI extends Bandmate
My (personal practise):
Most times, I extend my beans - i.e. fullName could be reused in other classes.
I use TypeConverters for UI improvements (i.e. red colors for negative values).
Note: for some special cases i use a render instead of databinding, i.e. for OLAP reporting (because the number of columns is variable).
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
What's wrong with the core methods?
Asked: 2011-03-16 04:53:44 +0800
Seen: 666 times
Last updated: May 26 '15