0

If statements in ZUL

asked 2011-06-09 15:50:19 +0800

SparkySpider gravatar image SparkySpider
444 1 3

Hi there,

Are there any ZK if tags? Or is there a smart way to do it with EL?

Of is the best way to use a JSP page with ZK tags in it?

Please let me know.

Thanks,

Mark

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2011-06-09 16:39:57 +0800

twiegand gravatar image twiegand
1807 3

Mark,

Does this help?

Todd

link publish delete flag offensive edit

answered 2011-06-10 02:54:26 +0800

SparkySpider gravatar image SparkySpider
444 1 3

Yeah!

link publish delete flag offensive edit

answered 2011-06-10 08:19:18 +0800

SparkySpider gravatar image SparkySpider
444 1 3

Hi there,

It doesn't seem to be working for me. I'm using a model with @notation as opposed to the $notation. Not too sure what the difference is, but I know it's not working :(

			
<listitem id="row" self="@{each='entity'}" value="@{entity}">
	<listcell >
		<image src="/resources/skins/foxbomb/warning.png" popup="notsaved" if="@{entity.parameters.mode=='new'}"/>
	</listcell>
</listitem>

Funnity enough, if I create a label and output @{entity.parameters.mode}, it does output the String 'new'.

Help much apprecaited.

link publish delete flag offensive edit

answered 2011-06-10 09:52:26 +0800

twiegand gravatar image twiegand
1807 3

updated 2011-06-10 09:53:59 +0800

Mark,

If memory serves, the if is part of EL. Because of that, it is only evaluated once and much earlier in the lifecycle than is databinding (@). Trying to mix the two will most likely only provide frustration.

From your code snippet, it appears that you want to display an image only when a value is set. If that is indeed the case, you can do that with a type converter. Consider the following example:

<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
 <zk>
	<window style="padding:25px;">
		<zscript>		
			import org.zkoss.zkplus.databind.TypeConverter;
			
			public class myTypeConverter implements TypeConverter {
				public Object coerceToBean(java.lang.Object val, org.zkoss.zk.ui.Component comp) {
					return null;
				}
			 
				public Object coerceToUi(java.lang.Object val, org.zkoss.zk.ui.Component comp) {

					if (val == "struct") {
						Image img = new Image("http://www.zkoss.org/img/front_page_icons/rss_16.png");
						if (((Listcell) comp).getLastChild() == null) {
							((Listcell) comp).appendChild(img);
						} 
					} else {
						Label lbl = new Label("regular");
						if (((Listcell) comp).getLastChild() == null) {
							((Listcell) comp).appendChild(lbl);
						} else {
							((Listcell) comp).getLastChild().setValue(lbl.getValue());
						}
					}
					return null;
				}
			}
			
			public class Person {
				private String firstName;
				private String lastName;
				private String type;

				public Person(String fn, String ln, String t) {
					setFirstName(fn);
					setLastName(ln);
					setType(t);
				}

				public String getFirstName() {
					return firstName;
				}
				public void setFirstName(String fn) {
					firstName = fn;
				}

				public String getLastName() {
					return lastName;
				}
				public void setLastName(String ln) {
					lastName = ln;
				}

				public String getType() {
					return type;
				}
				public void setType(String t) {
					type = t;
				}
			}
		
			 List persons = new ArrayList();
			 persons.add(new Person("Jonas", "Blane", "reg"));
			 persons.add(new Person("Bob", "Brown", "struct"));
			 persons.add(new Person("Mack", "Gerhardt", "reg"));
			 persons.add(new Person("Charles", "Grey", "reg"));
			 persons.add(new Person("Tom", "Ryan", "struct"));
	   
		</zscript>
	 
		<listbox rows="5" model="@{persons}" selectedItem="@{selected}" width="300px">
			<listhead>
				<listheader label="First Name" width="100px" />
				<listheader label="Last Name" width="100px" />
				<listheader label="Converted Value" width="100px" />
			</listhead>
			<listitem self="@{each=person}" value="@{person}">
				<listcell label="@{person.firstName}" />
				<listcell label="@{person.lastName}" />
				<listcell
					label="@{person.type, converter='myTypeConverter'}" />
			</listitem>
		</listbox>
		<space spacing="25px" orient="horizontal" />
		
		<cell align="right"><label value="Back-end value:  "/></cell><textbox value="@{selected.type}" />
	</window>
</zk>

If you run the above, you'll see that only the people that have a type of "struct" get an image shown. If you click on different rows, you'll see the raw value in the textbox below.

Hope that helps,

Todd

link publish delete flag offensive edit

answered 2011-06-10 10:55:03 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

for a quick explanation of if/foreach in relation to databinding, see this thread

if, foreach, etc., are evaluated at composition time and use EL for their expressions...

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-06-09 15:50:19 +0800

Seen: 2,543 times

Last updated: Jun 10 '11

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