0

Combo box value

asked 2014-02-05 19:42:49 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...
<combobox
                                                                model="@load(vm.patientModelList)" hflex="1"
                                                                width="85px" mold="rounded"
                                                                value="@bind(vm.patientCode)"
                                                                autodrop="true" autocomplete="true">
                                                                <template
                                                                    name="model">
                                                                    <comboitem
                                                                        label="@load(each.formattedName)"
                                                                        value="@load(each.code)" />
                                                                </template>
                                                            </combobox>

In the above code, i am expecting vm.patientcode should contain the code, but after selecting, it actually contains the formattedName.

If i change label = @load(each.code) then it works fine. But i want to display the name and i want the underlined code after selecting

what is the way to achieve that ?

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-02-11 09:54:53 +0800

MVarun gravatar image MVarun flag of India
268 1 6

Hi Mr.Senthil, Try This.

In ZUL..

<combobox id="cmbx_patient">
   <comboitem label="Patient1Name" value="patient1id">
   <comboitem label="Patient2Name" value="patient2id">
</combobox>

In Java Class..

cmbx_patient.addEventListener(Events.ON_SELECT, new EventListener() {
        public void onEvent(Event evt)throws Exception
        {
           cmbx_patient.setValue(cmbx_patient.getSelectedItem().getValue()+"");
        }
    });

Greetings...

M Varun.

link publish delete flag offensive edit

Comments

it is not recommended to modify the value of comboitem directly, the value of comboitem usually denotes the binded javabean

benbai ( 2014-02-17 01:25:18 +0800 )edit

@ benbai :: If we set readonly="true" to combobox we can avoid the change i think. What do you say?

MVarun ( 2014-02-18 11:38:29 +0800 )edit

just mentioned value is provided for access javabean from comboitem easily, you can still change it if needed however.

benbai ( 2014-02-21 10:50:50 +0800 )edit
0

answered 2014-02-10 03:49:12 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

Combobox will take the label of selected Comboitem as its value, you can use a custom comboitem to render what you want as below:

test.zul

<zk>
    <window apply="org.zkoss.bind.BindComposer"
        viewModel="@id('vm') @init('test.TestVM')">
        <combobox model="@load(vm.patientModelList)"
            value="@bind(vm.patientCode)"
            width="85px" mold="rounded"
            autodrop="true" autocomplete="true">
            <template name="model">
                <comboitem use="test.CustomComboitem" label="@load(each.code)"
                    displayLabel="@load(each.formattedName)" />
            </template>
        </combobox>
    </window>
</zk>

TestVM.java

package test;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.zkoss.zul.ListModelList;

public class TestVM implements Serializable {
    ListModelList _patientModelList;
    private String _patientCode = "";
    public ListModelList getPatientModelList () {
        if (_patientModelList == null) {
            List<Patient> patientList = new ArrayList<Patient>();
            for (int i = 0; i < 10; i++) {
                patientList.add(new Patient("Name_" + (i+1), i+1 + ""));
            }
            _patientModelList = new ListModelList(patientList);
        }
        return _patientModelList;
    }
    public String getPatientCode () {
        return _patientCode;
    }
    public void setPatientCode (String patientCode) {
        _patientCode = patientCode;
    }
}

Patient.java

package test;

public class Patient {
    private String _name;
    private String _code;
    public Patient (String name, String code) {
        _name = name;
        _code = code;
    }
    public String getName () {
        return _name;
    }
    public String getCode () {
        return _code;
    }
    public String getFormattedName () {
        return "Formatted " + getName();
    }
}

CustomComboitem.java

package test;

import org.zkoss.zul.Comboitem;

public class CustomComboitem extends Comboitem {
    private String _displayLabel;
    public CustomComboitem () {
        setWidgetOverride ("domLabel_", "function () {\n"
                + "         return zUtl.encodeXML(this._displayLabel || this.getLabel(), {pre: 1});\n"
                + "     }\n");
        setWidgetOverride ("setDisplayLabel", "function (v) {\n"
                + "         this._displayLabel = v;\n"
                + "     }\n");
    }
    public void setDisplayLabel (String displayLabel) {
        if (displayLabel == null) {
            displayLabel = "";
        }
        if (!displayLabel.equals(_displayLabel)) {
            _displayLabel = displayLabel;
            smartUpdate("displayLabel", _displayLabel);
        }
    }
    // override
    protected void renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer)
        throws java.io.IOException {
        super.renderProperties(renderer);
        render(renderer, "displayLabel", _displayLabel);
    }
}
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-02-05 19:42:49 +0800

Seen: 100 times

Last updated: Feb 11 '14

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