0

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

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

aflak gravatar image aflak
1 2

updated 2014-01-13 09:53:39 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...
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;
}

}

delete flag offensive retag edit

Comments

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 )edit

hi i cant publich my code

aflak ( 2014-01-13 08:26:48 +0800 )edit

you 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 )edit

i can send my code for you in email? because i don't know post code here :(

aflak ( 2014-01-13 08:33:51 +0800 )edit

just 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

3 Answers

Sort by ยป oldest newest most voted
1

answered 2014-01-13 14:08:16 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2611 3 8
http://emrpms.blogspot.in...

May this example helps

link publish delete flag offensive edit

Comments

nice example

chillworld ( 2014-01-13 14:13:02 +0800 )edit
0

answered 2014-01-13 10:35:29 +0800

chillworld gravatar image chillworld flag of Belgium
5322 4 9
https://github.com/chillw...

updated 2014-01-13 12:32:08 +0800

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.

link publish delete flag offensive edit
0

answered 2014-01-27 06:06:44 +0800

aflak gravatar image aflak
1 2

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>
link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

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

Seen: 45 times

Last updated: Jan 27 '14

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