Java 如何在ZK7中收听甚至从组合框中选择项目?
我正在使用MVC设计模式。在文件Java 如何在ZK7中收听甚至从组合框中选择项目?,java,zk,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">
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>
在文件控制器:FmCompressComposer.java
中,我尝试了以下方法(我的想法):
公共类FmCompressComposer扩展了BaseCustomComposer{
//....
@电线
专用组合框cbotoglezipunzip;
//....
//初始化组合框的值。
public ListModel getListTypeOfProcess(){
lstTypeOfCompress=newArrayList();
TypeOfCompressDTO t1=新的TypeOfCompressDTO(“1”,“Zip文件”);
TypeOfCompressDTO t2=新的TypeOfCompressDTO(“2”,“解压文件”);
lstTypeOfCompress.add(t1);
增加(t2);
listTypeOfProcess=新的ListModelList(lstTypeOfCompress,true);
返回进程的列表类型;
}
//听,甚至选择组合框中的项目。
在选择$cboZipUnzip()时公共无效{
searchDTO=新的FmCompressDTO();
searchDTO.setType(“1”);
//我的问题集中在这个方法上,在这一行,获取用户选择的值。searchDTO.setType(cbotoglezipunzip.getSelectedItem().getValue().toString());
List listDTO=fmCompressService.search(searchDTO);
if(listDTO!=null&!listDTO.isEmpty()){
ListModelList模型=新的ListModelList(listDTO);
model.setMultiple(true);
gridDataFmCompress.setModel(model);
刷新网格数据(空);
}
}
//...
}
请帮助我:在组合框中,当用户有事件选择时,调用方法。(在方法中,获取用户从组合框中选择的值)。我假设您的
BaseCustomComposer
正在扩展
如果是这样,您将严格遵守命名约定
由于组合框的id为cbofmcpress
,因此有线变量应为
// no need for @Wire
private Combobox cboFmCompress;
事件侦听器方法应为public void onSelect$cbofmcpress(事件){}
在这里你可以找到一把小提琴:我不知道你的问题是什么。是不是没有调用事件侦听器?谢谢。是的,我的方法事件侦听器不工作(在select$cboZipUnzip()上命名method
时,我可能会出错)。而且我无法获得用户选择的价值。它有效!帮助我从用户选择的组合框中获取值。修改问题中的上述代码片段,我尝试了searchDTO.setType(cbotoglezipunzip.getSelectedItem().getValue().toString())代码>但它不起作用。这将是searchDTO.setType(cbofmpress.getSelectedItem().getValue().toString())代码>然后。调试cbofmcpress.getSelectedItem().getValue().toString()
说了什么?我搞错了。我稍微改变一下,它就行了。
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);
}
}
//...
}
// no need for @Wire
private Combobox cboFmCompress;