-
FEATURED COMPONENTS
First time here? Check out the FAQ!
hi don't work selectedItem in my combo box i used class
org.zkoss.bind.converter.sys.ComboboxSelectedItemConverter
but don't work again
Here is my ZUL File
<window id="nodeTypeForm" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('ir.amelsystem.o18t.presentation.hierarchy.HierarchyFormVM')"
validationMessages="@id('vmsgs')" title="Hierarchy Type" mode="modal"
closable="true" border="normal" width="720px"
action="show: slideDown;hide: slideUp">
<caption image="images/config-16x16.png" />
<grid fixedLayout="true" width="700px"
form="@id('fx') @load(vm.item) @save(vm.item, before='submit')">
<columns>
<column />
<column />
<column />
<column />
</columns>
<rows>
<row>
<asteriskLabel value="Name" showStar="true" />
<textbox value="@bind(fx.name)" mold="rounded"
placeholder="Text" constraint="${vm.nameConstraint}" width="150px"
maxlength="100" />
<asteriskLabel value="Enabled" showStar="false" />
<checkbox checked="@bind(fx.enabled)" />
</row>
<row>
<asteriskLabel value="Hierarchy" showStar="true" />
<combobox model="@load(vm.hierarchyTypeList)"
selectedItem="@bind(fx.hierarchyTypeId)" autocomplete="false"
readonly="true" width="150px" autodrop="true" mold="rounded"
buttonVisible="true" placeholder="Select One"
constraint="no empty">
<template name="model" var="model">
<comboitem value="@load(model.id)"
label="@load(model.name)" />
</template>
</combobox>
<asteriskLabel value="Node Type" showStar="true" />
<combobox model="@load(vm.nodeTypeList)"
selectedItem="@bind(vm.item.nodeTypeId) @converter(vm.comboboxSelectedItemConverter)"
autocomplete="false" readonly="true" width="150px" autodrop="true"
mold="rounded" buttonVisible="true" placeholder="Select One"
constraint="no empty">
<template name="model" var="model">
<comboitem value="@load(model.id)"
label="@load(model.name)" />
</template>
</combobox>
</row>
<row>
<asteriskLabel value="Icon" showStar="true" />
<!--<textbox mold="@load(vm.iconList)" value="@load(fx.iconId)"></textbox> -->
<combobox model="@load(vm.iconList)"
autocomplete="false"
selectedItem="@bind(fx.iconId) @converter(vm.comboboxSelectedItemConverter) "
readonly="true" width="150px" autodrop="true" buttonVisible="true"
placeholder="Select One" constraint="no empty"
id="icon_combobox">
<template name="model" var="model">
<comboitem value="@load(model.id)"
label="@load(model.name)"
imageContent="@load(model.content) @converter(vm.iconConvertCombobox)">
</comboitem>
</template>
</combobox>
<asteriskLabel value="Description" showStar="False" />
<textbox value="@bind(fx.description)" multiline="true"
mold="rounded" placeholder="Text" width="150px" />
</row>
<row spans="4" align="right">
<hbox style="padding-right:42px">
<button id="submitBtn"
onClick="@command('submit', target=self)" mold="trendy"
label="@bind(item.id eq null?'Create':'Save') "
autodisable="self,cancelBtn" />
<button label="Cancel" id="cancelBtn" mold="trendy"
onClick="nodeTypeForm.detach()" autodisable="self,submitBtn" />
</hbox>
</row>
</rows>
</grid>
</window>
And java class
public class HierarchyFormVM implements IForm<hierarchy> {
@WireVariable
private HierarchyBiz hierarchyBiz;
@WireVariable
private NodeTypeBiz nodeTypeBiz;
@WireVariable
private HierarchyTypeBiz hierarchyTypeBiz;
@WireVariable
private IconBiz iconBiz;
private IconConverter iconConverter;
private IconConvertCombobox iconConvertCombobox;
private ComboConverter<Comboitem> comboConvert;
private Hierarchy item = new Hierarchy();
private Window window;
private Iterable<NodeType> nodeTypeList;
private Iterable<HierarchyType> hierarchyTypeList;
private Iterable<Icon> iconList;
private ComboboxSelectedItemConverter comboboxSelectedItemConverter ;
private Constraint nameConstraint = new Constraint() {
@Override
public void validate(Component comp, Object value)
throws WrongValueException {
String name = (String) value;
if (name == null || name.length() == 0)
throw new WrongValueException(comp, "Name is empty.");
if (item.getId() == null && hierarchyBiz.exists(name))
throw new WrongValueException(comp,
"Name is already Registered.");
}
};
public HierarchyFormVM() {
super();
iconConvertCombobox = new IconConvertCombobox();
iconConverter = new IconConverter();
comboboxSelectedItemConverter = new ComboboxSelectedItemConverter();
}
@Override
@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
this.window = (Window) view;
}
@Override
public Hierarchy getItem() {
return this.item;
}
public Constraint getNameConstraint() {
return nameConstraint;
}
@Override
@Init
public void init(@ExecutionArgParam("item") Hierarchy item) {
if (item != null) {
this.item = item;
} else
this.item.setEnabled(true);
this.nodeTypeList = this.nodeTypeBiz.findAll();
this.hierarchyTypeList = this.hierarchyTypeBiz.findAll();
this.iconList = this.iconBiz.findAll();
}
@Override
public void setItem(Hierarchy item) {
this.item = item;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
@Command("submit")
public void submit(@BindingParam("target") Component targetComponent) {
try {
Messagebox.show("Are you sure?", "Confirm", Messagebox.OK
+ Messagebox.CANCEL, Messagebox.EXCLAMATION,
new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
if ("onOK".equals(event.getName())) {
Hierarchy root = hierarchyBiz.getRoot();
if (item.getPid() == null) {
item.setPid(root == null ? -1L : root.getId());
}
hierarchyBiz.save(item);
window.detach();
Clients.showNotification("Action is done.",
true);
}
BindUtils.postGlobalCommand(null, null, "load",
null);
}
});
} catch (Exception e) {
e.printStackTrace();
window.detach();
Messagebox.show("Fail to Perform Action!", "Error", Messagebox.OK,
Messagebox.ERROR);
}
}
public Iterable<NodeType> getNodeTypeList() {
return nodeTypeList;
}
public Iterable<HierarchyType> getHierarchyTypeList() {
return hierarchyTypeList;
}
public Iterable<Icon> getIconList() {
return iconList;
}
public IconConverter getIconConverter() {
return iconConverter;
}
public IconConvertCombobox getIconConvertCombobox() {
return iconConvertCombobox;
}
public ComboboxSelectedItemConverter getComboboxSelectedItemConverter() {
return comboboxSelectedItemConverter;
}
}
Oke this is what I think you want to change is:
<combobox model="@load(vm.nodeTypeList)" selectedItem="@bind(vm.item.nodeTypeId) @converter(vm.comboboxSelectedItemConverter)" autocomplete="false" readonly="true" width="150px" autodrop="true" mold="rounded" buttonVisible="true" placeholder="Select One" constraint="no empty">
<template name="model" var="model">
<comboitem value="@load(model.id)" label="@load(model.name)" />
</template>
</combobox>
So you want that the @bind(vm.item.nodeTypeId) works. In your vm I don't see a getItem. You could better do :
<combobox model="@load(vm.nodeTypeList)" selectedItem="@bind(fx.nodeType) autocomplete="false" readonly="true" width="150px" autodrop="true" mold="rounded" buttonVisible="true" placeholder="Select One" constraint="no empty">
Greetz chill.
my problem fix by this way
<attribute name="onAfterRender" ><![CDATA[
if (nodeTypeForm.getAttribute("$VM$").item.hierarchyTypeId != null) {
int a = nodeTypeForm.getAttribute("$VM$").item.hierarchyTypeId.id;
int count = self.getItemCount();
for (int i = 0; i < count; i++) {
int index = self.getItemAtIndex(i).getValue();
if (index == a) {
self.setSelectedIndex(i);
}
}
}
]]></attribute>
Asked: 2014-01-13 08:04:16 +0800
Seen: 46 times
Last updated: Jan 27 '14
can u provide code? With this we just don't know what you are trying to do.
chillworld ( 2014-01-13 08:14:50 +0800 )edithi i cant publich my code
aflak ( 2014-01-13 08:26:48 +0800 )edityou can't or you may not? if its the last make a less complicated code to reproduse the problem and post that.
chillworld ( 2014-01-13 08:29:33 +0800 )editi can send my code for you in email? because i don't know post code here :(
aflak ( 2014-01-13 08:33:51 +0800 )editjust do an enter and set 4 spaces and paste your code (if not all code is shown you have to set the 4 spaces before that line)
chillworld ( 2014-01-13 08:38:20 +0800 )edit