0

How to Disable a Comboitem in Combobox

asked 2015-08-31 14:18:50 +0800

bodo gravatar image bodo
1

Hi there, I have two combobox and both of them has same model. I want to disable a comboitem that i select in the first combobox. I use setModel method with BindingListModelList for my second combobox. Because it's the only modellist that i can run correctly.

I tried this in my composer class:

this.secondComboBox.getItemAtIndex(this.firstComboBox.getSelectedIndex()).setDisabled(true);

It throws null pointer exception; but it looks make sense to me.

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-08-31 15:39:32 +0800

cyiannoulis gravatar image cyiannoulis
1201 10

It should work. The following example works just fine (ZK 7.0.5). Try to test it. Maybe something else is wrong with your models.

<zk>
<window title="MVC Various Tests" border="normal" apply="mvctest.MvcTestController">    
    <combobox id="cmbAreas" />
    <combobox id="cmbAreas2" /> 
</window>
</zk>


public class MvcTestController extends SelectorComposer<Component> {

    private static final long serialVersionUID = 1L;

    @Wire private Combobox cmbAreas;
    @Wire private Combobox cmbAreas2;

    private ListModel<String> areas;

    public void doAfterCompose(Component comp) throws Exception {

        super.doAfterCompose(comp);

        List<String> data = new ArrayList<String>();
        data.add("Greece");
        data.add("Germany");
        data.add("France");
        data.add("Spain");
        areas = new ListModelList<String>(data);        
        cmbAreas.setModel(areas);
        cmbAreas2.setModel(areas);
    }

    @Listen("onSelect = #cmbAreas")
    public void onSelectArea(SelectEvent event) {

        for (Comboitem i : cmbAreas2.getItems()) 
            i.setDisabled(false);

        int index = cmbAreas.getSelectedIndex();
        cmbAreas2.getItemAtIndex(index).setDisabled(true);

    }
}

/Costas

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
2 followers

RSS

Stats

Asked: 2015-08-31 14:18:50 +0800

Seen: 33 times

Last updated: Aug 31 '15

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