0

Can we concatenate @{bean.firstName} and @{bean.lastName}

asked 2011-03-16 04:53:44 +0800

dagarwal82 gravatar image dagarwal82
246 4

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)

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2011-03-16 05:42:57 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2011-03-16 05:43:15 +0800

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

link publish delete flag offensive edit

answered 2011-03-16 10:40:27 +0800

twiegand gravatar image twiegand
1807 3

updated 2011-03-16 10:44:58 +0800

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

link publish delete flag offensive edit

answered 2011-03-16 17:29:45 +0800

robertpic71 gravatar image robertpic71
1275 1

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).

link publish delete flag offensive edit

answered 2015-05-26 12:32:39 +0800

WilliamB gravatar image WilliamB
1609 1 6

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

link publish delete flag offensive edit

answered 2015-05-26 14:44:18 +0800

chillworld gravatar image chillworld flag of Belgium
5322 4 9
https://github.com/chillw...

What's wrong with the core methods?

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: 2011-03-16 04:53:44 +0800

Seen: 659 times

Last updated: May 26 '15

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