0

How to iterate over the List in ZK JSF?

asked 2008-12-01 12:25:09 +0800

ady1981 gravatar image ady1981
120 4

updated 2008-12-01 14:09:13 +0800

Hello,

I use ZK JSF and I would like to output values from a database.

But z:forEach attribute does not work.

For example, the following code does not work (where "solutions" is a List of Objects):
...
<z:rows >
<z:row z:forEach="${solutions}">
<z:label z:value="${each.solutionPK.taskId}" />
<z:label z:value="${each.solutionPK.solutionId}" />
<z:label z:value="${each.solutionPK.moduleId}" />
</z:row>
</z:rows>
...
So, how to iterate over the List?


Regards,

-Andrey

delete flag offensive retag edit

6 Replies

Sort by ยป oldest newest

answered 2008-12-05 04:40:54 +0800

PeterKuo gravatar image PeterKuo
481 2

updated 2008-12-05 06:42:57 +0800

First of all, ZK:forEach is not supported in JSF yet.
Please post it to feature request. Sorry for your inconvinience.

Second, use EL when mixing ZK and JSF, you have to think about which context does the variable belong. The syntax is different.

My suggestion, why not just use ZUL, and include it?

link publish delete flag offensive edit

answered 2009-01-12 15:59:18 +0800

sly3 gravatar image sly3
99 1

By the way, of this topics. I have a question. Is possible to iterate with forEach in a zul page a list of object? For Example
Person p=new Person("Tommy", "Lee", "12345");// (name, surname, number telephone)
list.add(p);
p=new Person("Jerry", "Sullivan", "56789");
list.add(p);
in a zul page:
<label value="{each}" forEach{p.name}>
<label value="{each}" forEach{p.surname}>

is possible?

link publish delete flag offensive edit

answered 2009-01-15 14:58:09 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

Use a <zk> tag as a brace tag.

<zk foreach="${list}">
<label value="${each.name}"/>
<label value="${each.surname}"/>
</zk>

link publish delete flag offensive edit

answered 2009-01-16 09:15:11 +0800

sly3 gravatar image sly3
99 1

Thank's a lot henrichen. It's the answer that I need :)

link publish delete flag offensive edit

answered 2009-01-17 17:52:36 +0800

sly3 gravatar image sly3
99 1

I Try what I Henrichen say but the zul page contains a blank window

This is the class
public class Vetrina extends Window{
private List listaBox = new ArrayList();

public Vetrina ()
{
Box box= new Box();
box.setLink("www.aaaaa.it");
box.setPreview("img/aaaa.gif");
box.setTitle("Famoso");
box.setSlide("img/AAAA.gif");
listaBox.add(box);
Box box2= new Box();
box2.setLink("www.bbbb.it");
box2.setPreview("img/bbb.jpg");
box2.setTitle("Altro");
box2.setSlide("img/bbb.jpg");
listaBox.add(box2);
Box box3= new Box();
box3.setLink("www.ccc.it");
box3.setPreview("img/ccc.jpg");
box3.setTitle("Messaggeria");
box3.setSlide("img/ccc.jpg");
listaBox.add(box3);
System.out.println(listaBox.toString());
Executions.getCurrent().getDesktop().getSession().setAttribute("lista", listaBox);


this is a zul file

<?page id="testZul" title=" New ZUL Title" cacheable="false"
language="xul/html" zscriptLanguage="Java" contentType="text/html;charset=UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>

<zk xmlns="http://www.zkoss.org/2005/zul"
xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">

<div align="center">
<window title="La vetrina di Euro2Box" use="Vetrina" xmlns:h="http://www.w3.org/1999/xhtml" border="normal" width="1024px">



<zscript><![CDATA[
List listaBox=(ArrayList)Executions.getCurrent().getDesktop().getSession().getAttribute("lista");
System.out.println(listaBox.get(0).getLink());
]]></zscript>
<zk forEach="${listabox}">
<label value="${each.link}"/>
<label value="${each.preview}"/>
<label value="${each.slide}"/>
<label value="${each.title}"/>
</zk>

</window>
</div>

</zk>

Please Can U help me? What's my mistake?

link publish delete flag offensive edit

answered 2009-01-17 20:05:11 +0800

sly3 gravatar image sly3
99 1

The problem was listBox instead of listbox... sorry :D

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: 2008-12-01 12:25:09 +0800

Seen: 659 times

Last updated: Jan 17 '09

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