0

String concatenation with data binding?

asked 2010-07-30 17:46:08 +0800

jnorris gravatar image jnorris
6

I'm just getting started with zk and am enjoying it so far. I have a question about the CRUD sample. Here is a snippet of the .zul from the example:

...
<listbox id="personslb" rows="10" model="@{mainCtrl.model}"
selectedItem="@{mainCtrl.selected}">
<listhead>
<listheader label="Name"/>
<listheader label="Title"/>
</listhead>
<listitem self="@{each=person}">
<listcell label="@{person.name}" />
<listcell label="@{person.title}" />
</listitem>
</listbox>
...

Is there an easy way to combine values that are returned from the @{} databinding expressions? For example, if I wanted the first column of the table to contain the person's name *and* title, I wish I could just do this:

<listcell label="@{person.name} @{person.title}" />

Since that doesn't work, what's the next best way? Do I have to use a renderer?

Thanks!
Jeff

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2010-07-30 19:27:54 +0800

Matze2 gravatar image Matze2
773 7

I would use a converter.

Something like the following should work:

public Object coerceToUi(Object val, Component comp) {
if (val instanceof Person) {
Person person = (Person) val;
return person.getName() + " " + person.getTitle();
}
return val;
}

the corresponding label should look like that:
label="@{person, converter='your.package.name.PersonNameTitleConverter'}"

Hope this helps.

link publish delete flag offensive edit

answered 2010-07-30 21:58:55 +0800

jnorris gravatar image jnorris
6

Thanks!

link publish delete flag offensive edit

answered 2023-11-14 02:54:14 +0800

chemFelix gravatar image chemFelix
0

Nowadays, you can do this with pure EL, see books.zkoss.org/zk-mvvm-book/8.0/databinding/elexpression.html#el-30-support

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: 2010-07-30 17:46:08 +0800

Seen: 571 times

Last updated: Nov 14 '23

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