ZK framework: I have two Comboboxes; How to clear the 2nd Combobox on selecting a different item on the first Combobox?

149 Views Asked by At

I am new to zk framework and I tried everything but nothing seems to work; I used

@Command
public void clearSelection(@BindingParam("listModel")ListModelList model) {
    if (model!=null) {
       model.clearSelection();
    }
}

and on the 2nd combobox I used:

onChange="@command('clearSelection', listModel=self.model)";

It is clearing the text of the second combobox but the list is not being populated on the second combobox; I want when the value of the first combobox changes then the text that is displayed on the second combobox to be removed the above function clears the text but the data is not getting binded on the second combobox

i want:

combobox 1 -> (value) combobox 2 -> (value)

combobox 1 -> (another value) combobox 2 -> previously displayed data to get clear whilst the data pertaining to (another value) to be displayed

I tried using @bind instead of @load but cannot comeup with a solution

Thankyou in advance

1

There are 1 best solutions below

0
Hawk On

For those who new to ZK, I recommend using MVC pattern (using Composer) because it's easy to start.

when the value of the first combobox changes then the text that is displayed on the second combobox to be removed

onChange="@command('clearSelection', listModel=self.model)"

This command binding should fulfill this requirement.

but the data is not getting binded on the second combobox

I don't see you bind any model to the 2nd combobox. I suppose there should be 2nd model like:

<combox model="@init(vm.model2)"/>

Besides, you usually don't need to pass a ListModel into a command method like:

public void clearSelection(@BindingParam("listModel")ListModelList model)

Since the ViewModel should already have that ListModel object.