0

Zk Chosenbox getSelection

asked 2015-10-01 20:53:37 +0800

javiut gravatar image javiut flag of Venezuela, Bolivarian Republic of
90 1 5

updated 2015-10-02 20:27:40 +0800

I have a Chosebox i am completely new to this api i select some items but i couldn't find back i mean i have try

BindingListModelList getSelection()

but returns empty i have try

chosen.getSelectedObjects()

I follow this example http://www.zkoss.org/zkdemo/zkpeandee/comboboxchosenbox but i could not find a way to retrieve the selected objects.

but nothing worked any tip thanks a lot.

UPDATE I was using a ItemRender like this

public final class CustomChoseBoxRender implements org.zkoss.zul.ItemRenderer<NotNullIntegerStringEntry>
{    
public String render(final Component owner,final NotNullIntegerStringEntry data,final int index) throws Exception
  {return data.getValue();}
}

when i set the render to the chosenbox the getSelection() method always return a empty set.

box.setItemRenderer(new CustomChoseBoxRender());
<chosenbox itemRenderer="@{render}"/>

I have try to set it in both java and in and zul but the results are the same.

Is this a bug any workaround?

I have create a Fiddle as show this bug in 6.5.3 but works ok in 7.5.1

http://zkfiddle.org/direct/13sio2p/1/v6.5.3-Chosebox-getSelection?run=2vphvaf

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-10-03 10:15:00 +0800

JoeHuang gravatar image JoeHuang
1126 2

updated 2015-10-03 10:18:02 +0800

hi Javiut:

It's best to use a model to do all the operation instead of using a component.

Because a model has deal with all the possible situations, using a component would break the operations a model do.

Here is an example.

<zk>
    <hlayout apply="org.support.simulate6.MailContactsController">
        <chosenbox id="contacts" width="100px" />
        <button id="send" label="print" />
    </hlayout>
    <label id="output"/>
</zk>


public class MailContactsController extends SelectorComposer<Component> {

    @Wire("#contacts")
    private Chosenbox contactsbox;

    @Wire("#output")
    private Label output;

    private ListModelList<String> contacts;

    @Override
    public void doAfterCompose(Component comp) throws Exception {
        super.doAfterCompose(comp);

        contacts = new ListModelList<String>();
        contacts.add("[email protected]");
        contacts.add("[email protected]");
        contacts.add("[email protected]");
        contactsbox.setModel(contacts);
    }

    @Listen("onClick=#send")
    public void send() {
        String contact = "";
        Iterator<String> contactInter = contacts.getSelection().iterator();
        while (contactInter.hasNext()) {
            contact += contactInter.next();
            contact += " ";
        }
        output.setValue(contact);
    }

}
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

Follow
1 follower

RSS

Stats

Asked: 2015-10-01 20:53:37 +0800

Seen: 21 times

Last updated: Oct 03 '15

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