Getting data from decimalbox in listbox

asked 2020-06-07 22:54:23 +0800

shgleb94 gravatar image shgleb94
31 1

Hi there! I have an issue with gathering data from bunch of decimalboxes which are stored in a listbox via listcell. Here's the code:

ZUL: listbox style="border:none" id="Grid" multiple="true" rows="20" width="100%" selectedItem="@{feemain$composer.current}"> <listhead sizable="true"> <listheader label="a" width="70%"/> <listheader label="b" width="30%" sort="auto"/> </listhead> </listbox>

Java: this.Grid.setModel(new BindingListModelList(Service.getCodes(branch, alias) , true)); this.Grid.setItemRenderer((ListitemRenderer)new ListitemRenderer() { public void render(final Listitem row, final Object data) throws Exception { String Data = (String) data; Decimalbox db = new Decimalbox(); row.appendChild(new Listcell(Data)); Listcell haddacc = new Listcell(); haddacc.appendChild(db); row.appendChild(haddacc); } });

Quantity of rows is controlled by Grid.setModel as the quantity of Decimalboxes too. I don't have any id of them to point.

I tried

System.out.print("item: "+HumoGrid.getItems().get(0).toString());

but it gives me this:

item: Listitem f2DP51>

Also tried

System.out.print("item: "+((Decimalbox)HumoGrid.getItems().get(0)).getValue().toString());

but it returns

org.zkoss.zul.Listitem cannot be cast to org.zkoss.zul.Decimalbox

So how can I get the data from these decimalboxes? Thanks in advance!

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted

answered 2020-06-08 12:11:17 +0800

MDuchemin gravatar image MDuchemin
2560 1 6
ZK Team

Hi there,

Welcome on the forums :)

The structure of listbox is

            content (including the decimalbox)

listbox.getItems() will return a collection of Listitem objects, which is to say roughly, a list of Objects representing the rows currently existing in the listbox. This may or may not be the full list of possible rows, and may or may not be the same length as the model (depending on paging and render on demand)

What are you trying to do? :) Are you retrieving "form" data at the end of user inputs? Or are you accessing data in an event listener? There is almost always a better approach to retrieving data than searching the component tree manually.

Side note: this @{feemain$composer.current} looks like the old (ZK 3) data binding syntax. Which ZK version are you running? This might impact how to best retrieve that data.

Also, bumped your karma for links. I'd recommend the zkfiddle if you'd like to send code samples.

link publish delete flag offensive edit


Hello! Yep, I have to retrieve data from decimalboxes at the end of user inputs and this data must be connected with labels, which is uploaded by setModel. For example, Costco: 100 BestBuy: 253 And I have to get the String "Costco" and BigDecimal "100" to insert in the table after user presses Save.

shgleb94 ( 2020-06-08 17:11:29 +0800 )edit

I use ZK 5, this code I took from friend's project. This thing works so I never thought about it getting old :) Is there new ways to get current Object in new versions of ZK?

shgleb94 ( 2020-06-08 17:19:27 +0800 )edit

answered 2020-06-16 16:50:33 +0800

MDuchemin gravatar image MDuchemin
2560 1 6
ZK Team


You can set an ID on each of your target components, then query them to retrieve the component at the end, but that feels like overkill.

Since you are using the old data-binding syntax, you can consider using the tempalte + databinding syntax to write back to the data object directly, which you will then have control over in your Java class when submitting. Here's the archive links to the old docs on that topic : Web Format (ZK3) PDF format (ZK5)

If you don't want to go there, you can just use the onChange event to retrieve data when the user enters it in the component.

After all that, my actual recommendation would be to either move to MVC or MVVM with the current APIs, since you will find way better doc and examples on the latest versions ;) MVVM has a similar structure to the old databinding, so it could be the smoother transition. Then again, I'm aware that might be overkill if you are only changing a few screens on the app, so... your call there :D

link publish delete flag offensive edit


Thank you! I think that for this task I'll use old methods, thanks for links! And for further similar projects I need to learn things which you described in your message's last paraghraph.

shgleb94 ( 2020-06-17 14:18:35 +0800 )edit

Happy to help ;) here's some extra resources on the patterns I mentioned:

MDuchemin ( 2020-06-17 15:44:25 +0800 )edit
Your answer
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

1 follower



Asked: 2020-06-07 22:54:23 +0800

Seen: 9 times

Last updated: Jun 16 '20

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