gpt4 book ai didi

java - ZK 7中如何收听甚至从组合框中选择项目?

转载 作者:行者123 更新时间:2023-11-30 07:52:53 25 4
gpt4 key购买 nike

我使用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;
}

}

在文件 Controller :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);
}
}

//...

}

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

最佳答案

我假设您的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

关于java - ZK 7中如何收听甚至从组合框中选择项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33120026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com