Custom Component SelectedItem Bind

asked 2018-03-08 23:23:20 +0800

rohit12sh gravatar image rohit12sh
13 2

I am working on creating a new Custom Component and unable to bind a controller's property to the SelectedItem annotation property of my custom component. My idea is that any one who passes my Custom component SelectedItem annotation, I should be able to retrieve it in my component and assign it myself to the ListBox's SelectedItem property. This will give flexibility to the users of my component to not worry about the internals and the component will be re-usable.

Problem is that I am not able to get/set the Controller value in my custom component. I get NULL. Can someone please help me resolve this issue or point me to the right direction? Here is the code:

<bandbox id="filterDropdownBandBox" instant="true" readonly="false">
    <bandpopup id="filterDropdownBandPopup" style="max-height:250px;overflow-x:hidden">
        <listbox id="listBox" hflex="1" rows="0" >
             <template name="model">
                     <listcell label="${each.label}" />

public class FilterDropdown extends Div implements IdSpace {

    private Listbox listBox;
    private Bandpopup filterDropdownBandPopup;
    private Bandbox filterDropdownBandBox;

    private ListModelList<GenericNameValuePair> lbModel;

    public FilterDropdown() {
        Executions.createComponents("/filterDropdown.zul", this, null);
        Selectors.wireComponents(this, this, false);
        Selectors.wireEventListeners(this, this);
    public void setSelectedItem(Listitem l) // getting NULL here
     public void saveSelection() {

     public Listitem getSelectedItem() {
         return listBox.getSelectedItem();


This is how I added this component to lang-addon.xml file


And this is how I am using my custom component in other ZUL files

    <filter-dropdown id="filterProjDropdown" selectedItem="@DDBIND{XYZCtrl.bean.
delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-03-12 15:40:15 +0800

chillworld gravatar image chillworld flag of Belgium
5357 4 9

First of all, keep to the normal annotation like @load(), @save() or @bind()`.

Now, mine first suggestion is to throw your zul away.
Implement the AfterCompose interface in your component and add all the items there with a renderer.
It makes it easier for anyone to change that component and it will be more performent.

Secondly, use the correct annotation in your class :


Like this your lang-addon.xml should look like :


And as last :

You need to inform the binder that there was a change in the selectedItems :

Events.postEvent("onSelect", FilterDropdown.this, selectedItems);

You should handle this in an eventlistener attached to the bandbox.

If you want an advanced working component code including in how to export it to a separate jar, please check out mine github project.

link publish delete flag offensive 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




Asked: 2018-03-08 23:23:20 +0800

Seen: 14 times

Last updated: Mar 12 '18

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