Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9012717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:04:36+00:00 2026-06-16T03:04:36+00:00

I will want to use Data binding in Java Class rather than @bind With

  • 0

I will want to use Data binding in Java Class rather than

@bind

With each ListCell in Listbox.
I tried with this example

My ZUl File…

<zk>
  <window border="normal" title="hello" apply="org.zkoss.bind.BindComposer"
        viewModel="@id('vm') @init('com.test.binding.TestRenderer')" >
     <button label="ClickMe" id="retrieve"
                        onClick="@command('onOK')">
                    </button>
    <div height="800px">
      <listbox model="@load(vm.model)" itemRenderer="@load(vm.itemRenderer)" vflex="true" multiple="true"/>
    </div>
  </window>
</zk>

My Java Class or ViewController…..

package com.test.binding;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.zk.ui.Component;
import org.zkoss.zkplus.databind.AnnotateDataBinder;
import org.zkoss.zkplus.databind.Binding;
import org.zkoss.zkplus.databind.BindingListModelList;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;
import org.zkoss.zul.Textbox;


public class TestRenderer {

    ListModelList model = new ListModelList();
    private AnnotateDataBinder binder;

    @AfterCompose
    public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
        binder = new AnnotateDataBinder(view);
     List persons = new ArrayList();    
     model.add(new Person("David", "Coverdale"));
     model.add(new Person("Doug", "Aldrich"));
     model.add(new Person("Reb", "Beach"));
     model.add(new Person("Michael", "Devin"));
     model.add(new Person("Brian", "Tichy"));


        binder.loadAll(); 


    }

    public void setModel(ListModelList model) {
        this.model = model;
    }

    public ListModel getModel() {

        return model;
    }

    // method for ZK 6
    public ListitemRenderer getItemRenderer() {
        ListitemRenderer _rowRenderer = null;
        if (_rowRenderer == null) {

            _rowRenderer = new ListitemRenderer() {
                public void render(final Listitem item,   Object object,
                        int index) throws Exception {
                    final Person dataBean = (Person) object;

                    binder.bindBean(item.getId() , dataBean);

                    Listcell cell = new Listcell();
                    Textbox name = new Textbox();
                    name.setValue(dataBean.getFirstName());
                    System.out.println(item.getId()+ "------------------>"+item.getId() + ".name");
                    //binder.addBinding(name, "value", item.getId()+i + ".name", null, null, "both", null, null, null, null);
                    //binder.addBinding(name, "value",item.getId() + ".name", new String[] {}, "none", "both", null);
                    cell.appendChild(name);
                    //cell.addAnnotation(cell, "bind", null);
                    cell.setParent(item);

                }
            };
            binder.saveAll();
            binder.loadAll();
        }
        return _rowRenderer;
    }
    @Command
    public void onOK() {
        binder.saveAll(); //load Inputfields from Form, Constraints will be performed

        binder.loadAll(); 
       Collection<Binding> test =  binder.getAllBindings();
        System.out.println(model);
      }
    public class Person {
        private String firstName;
        private String lastName;

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

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

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

    }

    @Command
     public void clickMe(){
        BindingListModelList blml =  (BindingListModelList) getModel();

        for (Object object : blml) {
          System.out.println(Integer.parseInt((String) object));
        }
    }
}

Can any one give me the Demo Example How Binding should work with

getItemRendered()

In Listbox

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:04:38+00:00Added an answer on June 16, 2026 at 3:04 am

    In my opinion, using ListitemRenderer with MVVM is not so bad, sometimes it can be the ‘bridge’ between zul page and ViewModel, and it can be considered as a part of component (since once you assign a model, listbox will use default renderer to render item if you do not assign a template or a custom renderer) (see List Model). If there is nothing bad that assign only model and render items by default renderer, there is nothing bad assign both model and custom renderer to render items.

    Let’s define what the ‘good’ is at first:
    — The zul file do not need to know how ViewModel works, just ask for data and trigger command as needed.
    — The ViewModel do not need to know anything in zul page, just provide data and process some predefined event.

    Now thinking about a simple scenario like the one described in the official document:
    Performing Actions on Events

    see this line

    onClick="@command('deleteOrder', cartItem=cartItem)"
    

    and this line

    public void deleteOrder(@BindingParam("cartItem") CartItem cartItem)
    

    In this case, the zul page need to know bring the param to deleteOrder command while event triggered, and even have to know the param should assign the variable named cartItem in ViewModel. On the other hand, the ViewModel need to retrieve the param passed from zul page.

    This is obviously not the ‘good’ situation.

    With the ListitemRenderer, let’s say ShoppingcartOrderlistItemRenderer, we can simply post an event to Listbox (e.g., onDeleteOrder) with the required data, then make it becomes

    <listbox onDeleteOrder="@command('deleteOrder')" ...
    

    and

    public void deleteOrder(@ContextParam(ContextType.TRIGGER_EVENT) DeleteOrderEvent event) {
        getShoppingCart().remove(event.getProductId());
    }
    

    Rely on an event instead of rely on a param defined in zul page, I think this is more robust.

    Finally, still have to say, just personal opinion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to use stripes in our new project. This will take care of
I'm unable to use data binding in the ItemContainerStyle for a ListBox in Silverlight
I have a link, with which i want use plus, which will change color
I want to use ADO.NET Prepare command will increase performance if query is repeatevely
I want to use vba to take a screenshot (which will then be sent
I want to use an initialization function that will be called after a user
I want to use an Abstract action for JFileChooser buttons because there will be
I want to use regular expression same way as string.Format. I will explain I
I want to use JDBC to access a MySQL database. What or will an
First of all, I don't want to use a join because that will make

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.