-
FEATURED COMPONENTS
First time here? Check out the FAQ!
following does not work :
<window id="win" apply="org.me.MyController">
<grid id="grid" >
<rows >
<row>
<panel forEach="@{win$MyController.myList}">
<panelchildren>
<label value="@{each.name}"></label>
</panelchildren>
</panel>
</row>
</rows>
</grid>
class MyController {
List<MyBean> myList;
//docomposeafter, getter/setter
}
class MyBean {
private String name;
//getter / setter
}
dagarwal82,
The problem is that you are mixing EL and data binding which happen at two different times in the ZK lifecycle.
If you want to continue using forEach, simply changing your @ for $ should do the trick. So, instead of:
@{each.name}
Use
${each.name}
Here is a complete, runnable example:
<zk> <window> <zscript> public class Person { private String firstName; public Person(String fn) { setFirstName(fn); } public String getFirstName() { return firstName; } public void setFirstName(String fn) { firstName = fn; } } List Persons = new ArrayList(); Persons.add(new Person("John")); Persons.add(new Person("Paul")); Persons.add(new Person("George")); Persons.add(new Person("Ringo")); </zscript> <grid id="grid" > <rows> <row> <panel forEach="${Persons}"> <panelchildren> <label value="${each.firstName}"></label> </panelchildren> </panel> </row> </rows> </grid> </window> </zk>
Hope that helps,
Todd
Does it mean I have to use zscript. I was avoiding zscript at all in my app ( as I read it has few performance issues).
Any solution If I could use databinding only to create as many panels as the size of my list
dagarwal82,
I was just using zscript so you could see a fully-runnable example. Just remember that Expression Language statements are resolved early in the lifecycle and they only happen once. Therefore, they are good for static things (you cannot use EL to change values) such as field labels - especially when you have multi-language issue to contend with. More information on EL can be found here.
Unless there are some specific requirements you didn't mention, there really isn't a need for all those panels in your example. Depending on how your data is structured, you could use databinding and a component that supports an applicable model (like grid or listbox). An example of this might be:
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?> <zk> <zscript> public class Car { private String owner; private String mileage; private String color; private String brand; public Car(String o, String m, String c, String b) { setOwner(o); setMileage(m); setColor(c); setBrand(b); } public String getOwner() { return owner; } public void setOwner(String o) { owner = o; } public String getMileage() { return mileage; } public void setMileage(String m) { mileage = m; } public String getColor() { return color; } public void setColor(String c) { color = c; } public String getBrand() { return brand; } public void setBrand(String b) { brand = b; } } List Cars = new ArrayList(); Cars.add(new Car("Smith", "8,776", "Red", "Ferrari")); Cars.add(new Car("Jones", "1,250", "Blue", "Maserati")); Cars.add(new Car("Williams", "92,270", "White", "Pinto")); </zscript> <window id="main" style="padding: 25px;"> <grid id="myGrid" fixedLayout="true" model="@{Cars}" > <columns> <column label="Owner" style="font-weight: bold;"/> <column label="Color" style="font-weight: bold;"/> <column label="Brand" style="font-weight: bold;"/> <column label="Mileage" style="font-weight: bold;"/> </columns> <rows> <row self="@{each=Car}"> <cell><label value="@{Car.Owner}" /></cell> <cell><label value="@{Car.Color}" /></cell> <cell><label value="@{Car.Brand}" /></cell> <cell><label value="@{Car.Mileage}" /></cell> </row> </rows> </grid> </window> </zk>
Again, I'm only using zscript for the example. You could just as easily create java classes that contain the same things.
If you are wanting to control how many columns are created, I suspect you'll have to utilize your own renderer. For that, have a look here. It is an older document but still has merit for your situation.
I hope that helps a little.
Regards,
Todd
Asked: 2011-03-12 04:20:38 +0800
Seen: 388 times
Last updated: Mar 14 '11