Revision history [back]

click to hide/show revision 1
initial version

asked 2014-01-13 08:04:16 +0800

aflak gravatar image aflak

how use org.zkoss.bind.converter.sys.ComboboxSelectedItemConverter

hi don't work selectedItem in my combo box i used class org.zkoss.bind.converter.sys.ComboboxSelectedItemConverter but don't work again

how use org.zkoss.bind.converter.sys.ComboboxSelectedItemConverter

hi 
don't work selectedItem in my combo box i used class  org.zkoss.bind.converter.sys.ComboboxSelectedItemConverter but don't work again

again <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>

how use org.zkoss.bind.converter.sys.ComboboxSelectedItemConverter

hi 
don't work selectedItem in my combo box i used class   org.zkoss.bind.converter.sys.ComboboxSelectedItemConverter but don't work again
<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>
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;
}
 }

how use org.zkoss.bind.converter.sys.ComboboxSelectedItemConverter

hi  don't work selectedItem in my combo box i used class   org.zkoss.bind.converter.sys.ComboboxSelectedItemConverter class

org.zkoss.bind.converter.sys.ComboboxSelectedItemConverter but don't work again again

<window id="nodeTypeForm" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('ir.amelsystem.o18t.presentation.hierarchy.HierarchyFormVM')" validationMessages="@id('vmsgs')" apply="org.zkoss.bind.BindComposer" viewmodel="@id('vm') @init('ir.amelsystem.o18t.presentation.hierarchy.HierarchyFormVM')" validationmessages="@id('vmsgs')" title="Hierarchy Type" mode="modal" mode="modal" closable="true" border="normal" width="720px" width="720px" action="show: slideDown;hide: slideUp"> <caption image="images/config-16x16.png" /> <grid fixedLayout="true" width="700px" fixedlayout="true" width="700px" form="@id('fx') @load(vm.item) @save(vm.item, before='submit')"> <columns> <column /> <column /> <column /> <column /> <column/> <column/> <column/> <column/> </columns> <rows> <row> <asteriskLabel <asterisklabel value="Name" showStar="true" /> showstar="true"/> <textbox value="@bind(fx.name)" mold="rounded" mold="rounded" placeholder="Text" constraint="${vm.nameConstraint}" width="150px" maxlength="100" /> <asteriskLabel width="150px" maxlength="100"/> <asterisklabel value="Enabled" showStar="false" /> showstar="false"/> <checkbox checked="@bind(fx.enabled)" /> checked="@bind(fx.enabled)"/> </row> <row> <asteriskLabel <asterisklabel value="Hierarchy" showStar="true" /> showstar="true"/> <combobox model="@load(vm.hierarchyTypeList)" selectedItem="@bind(fx.hierarchyTypeId)" model="@load(vm.hierarchyTypeList)" selecteditem="@bind(fx.hierarchyTypeId)" autocomplete="false" readonly="true" width="150px" autodrop="true" mold="rounded" buttonVisible="true" mold="rounded" buttonvisible="true" placeholder="Select One" One" constraint="no empty"> <template name="model" var="model"> <comboitem value="@load(model.id)" label="@load(model.name)" /> label="@load(model.name)"/> </template> </combobox> <asteriskLabel <asterisklabel value="Node Type" showStar="true" /> showstar="true"/> <combobox model="@load(vm.nodeTypeList)" selectedItem="@bind(vm.item.nodeTypeId) model="@load(vm.nodeTypeList)" selecteditem="@bind(vm.item.nodeTypeId) @converter(vm.comboboxSelectedItemConverter)" autocomplete="false" autocomplete="false" readonly="true" width="150px" autodrop="true" mold="rounded" buttonVisible="true" mold="rounded" buttonvisible="true" placeholder="Select One" One" constraint="no empty"> <template name="model" var="model"> <comboitem value="@load(model.id)" label="@load(model.name)" /> value="@load(model.id)" label="@load(model.name)"/> </template> </combobox> </row> <row> <asteriskLabel <asterisklabel value="Icon" showStar="true" /> <!--<textbox mold="@load(vm.iconList)" value="@load(fx.iconId)"></textbox> --> showstar="true"/>

                 <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 
class

public class HierarchyFormVM implements IForm<Hierarchy> { 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;
}
 }

}

how use org.zkoss.bind.converter.sys.ComboboxSelectedItemConverter

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"> <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"/>

                 <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;
}

}

how use org.zkoss.bind.converter.sys.ComboboxSelectedItemConverter

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')" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('ir.amelsystem.o18t.presentation.hierarchy.HierarchyFormVM')"
validationMessages="@id('vmsgs')" title="Hierarchy Type" mode="modal" mode="modal"
closable="true" border="normal" width="720px" width="720px"
action="show: slideDown;hide: slideUp">
 <caption image="images/config-16x16.png" />
<grid fixedlayout="true" width="700px" fixedLayout="true" width="700px"
    form="@id('fx') @load(vm.item) @save(vm.item, before='submit')">
     <columns>
                <column/>
                <column/>
                <column/>
                <column/>
        <column />
        <column />
        <column />
        <column />
    </columns>
     <rows>
         <row>
                    <asterisklabel <asteriskLabel value="Name" showstar="true"/>
        showStar="true" />
            <textbox value="@bind(fx.name)" mold="rounded" 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" maxlength="100"/>
                    <asterisklabel value="Enabled" showstar="false"/>
                    <checkbox checked="@bind(fx.enabled)"/>
                </row>
                <row>
                    <asterisklabel value="Hierarchy" showstar="true"/>
        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.hierarchyTypeList)" selecteditem="@bind(fx.hierarchyTypeId)" 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" mold="rounded" buttonvisible="true" buttonVisible="true"
                placeholder="Select One" constraint="no empty">
        empty"
                id="icon_combobox">
                <template name="model" var="model">
                     <comboitem value="@load(model.id)" label="@load(model.name)"/>
        value="@load(model.id)"
                        label="@load(model.name)"
                        imageContent="@load(model.content) @converter(vm.iconConvertCombobox)">
                    </comboitem>
                </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"/>
                    

                 <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" 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()"
                        id="cancelBtn" mold="trendy"
                    onClick="nodeTypeForm.detach()" autodisable="self,submitBtn" />
             </hbox>
         </row>
     </rows>
 </grid>
</window>



</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;
}

}

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More