如何在ZK 7中从组合框中选择项目?

时间:2015-10-14 08:13:02

标签: java zk

我使用的是MVC设计模式。在文件FmCompress.zul中,我有:

<combobox id="cboFmCompress" model="${$composer.listTypeOfProcess}" mold="rounded" hflex="1">
    <attribute name="onCreate">self.setSelectedIndex(1);</attribute>
    <template name="model">
        <comboitem label="${each.typeOfCompress}" value="${each.typeOfCompressId}"></comboitem>
    </template>
</combobox>

组合框模型:TypeOfCompressDTO.java

public class TypeOfCompressDTO {

    private String typeOfCompressId;
    private String typeOfCompress;

    public TypeOfCompressDTO() {
    }

    public TypeOfCompressDTO(String typeOfCompressId, String typeOfCompress) {
        this.typeOfCompressId = typeOfCompressId;
        this.typeOfCompress = typeOfCompress;
    }

    public String getTypeOfCompressId() {
        return typeOfCompressId;
    }

    public void setTypeOfCompressId(String typeOfCompressId) {
        this.typeOfCompressId = typeOfCompressId;
    }

    public String getTypeOfCompress() {
        return typeOfCompress;
    }

    public void setTypeOfCompress(String typeOfCompress) {
        this.typeOfCompress = typeOfCompress;
    }

}

在文件控制器中:FmCompressComposer.java,我尝试这样的事情(我的想法):

public class FmCompressComposer extends BaseCustomComposer<FmCompressService, FmCompressDTO> {
     //....    

    @Wire
    private Combobox cboToggleZipUnzip;

    //....

    // initialize value for combo box.
    public ListModel<TypeOfCompressDTO> getListTypeOfProcess() {
        lstTypeOfCompress = new ArrayList<TypeOfCompressDTO>();
        TypeOfCompressDTO t1 = new TypeOfCompressDTO("1", "Zip file");
        TypeOfCompressDTO t2 = new TypeOfCompressDTO("2", "Unzip file");
        lstTypeOfCompress.add(t1);
        lstTypeOfCompress.add(t2);
        listTypeOfProcess = new ListModelList(lstTypeOfCompress, true);
        return listTypeOfProcess;
    }

     // Listen even select item in combo box.
     public void onSelect$cboZipUnzip(){   
        searchDTO = new FmCompressDTO();    
        searchDTO.setType("1");        
        // my problem focus at this method, and at this line, get value what user choosen. searchDTO.setType(cboToggleZipUnzip.getSelectedItem().getValue().toString());
        List<FmCompressDTO> listDTO = fmCompressService.search(searchDTO);
        if (listDTO != null && !listDTO.isEmpty()) {
            ListModelList model = new ListModelList(listDTO);
            model.setMultiple(true);
            gridDataFmCompress.setModel(model);
            refreshGridData(null);
        }
    }

    //...

}

请帮帮我:在组合框中,当用户选择事件时,调用方法。(在方法中,获取用户从组合框中选择的值)。

1 个答案:

答案 0 :(得分:1)

我认为您的BaseCustomComposer正在延长GenericForwardComposer

如果是这样,您将严格遵守命名约定。

由于你的组合框的id是cboFmCompress,你的有线变量应该是

// no need for @Wire
private Combobox cboFmCompress;

并且事件监听器方法应该是
    public void onSelect$cboFmCompress(Event event) {}

在这里你可以找到一个最小化的zkfiddle:http://zkfiddle.org/sample/3hnhc92/2-SO-33120026