-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
Yeah!
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.
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
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...
Asked: 2011-06-09 15:50:19 +0800
Seen: 2,543 times
Last updated: Jun 10 '11