0

How do you set Listcell label from method call in ViewModel

asked 2013-07-25 16:01:42 +0800

TiredOfSearching gravatar image TiredOfSearching
1

I'm a total n00b here.

Here's what I'm trying to do:

    <template name="model">
        <listitem>      
            <listcell label="@load(each.clientId)"/>
            <listcell label="@load(each.partId)"/>
...

This shows me the clientId, partId, etc. However, instead of showing the clientId, I want to show the client name, which is not part of my model. I created a method in the ViewModel to get this name from an id passed as a parameter.

Now, I hoped to be able to use something like:

<listcell label="@load(each.getClientName(each.clientId))"/>

But, as you can guess, it fails miserably...

Can someone give me a hint please. I really need it...

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2013-07-25 20:00:01 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

There can be a plenty of way to do this one thing i can suggest you to create a class name something DataBean which will contain all the records which you will want to display to user.So your DataBean Class Could be something like this

public class DataBean{
String name;
String parentID;
//Getter,Setter of above varaible
}

Now when you are creating your model give this DataBean class to the model something like this

List<DataBean> dataList = new ArrayList<>();

here you can see dataList would contain all the record of type DataBean class so you do not need to write any complex logic into the ZUL file.

Rather than you can write logic in Java Class to set the values in DataBean class.

link publish delete flag offensive edit
0

answered 2013-07-26 07:32:18 +0800

khcyt gravatar image khcyt
216 1 1

The following example works and uses the function getClientName.

Kai

<?xml version="1.0" encoding="UTF-8"?>

<zk> <style> .red { color: red; } </style> <zscript>

    class A
    {
        public A(String s, Long v, Boolean is_group)                    { s_= s; v_= v; is_group_= is_group; }

        public String getLabel()        { return s_; }
        public Boolean isGroup()        { return is_group_; }
        public Long getValue()          { return v_; }

        public String getClientName(Long v)     { return s_+ " -- "+ v.toString(); }

        String s_= null;
        Long v_= null;
        Boolean is_group_= null;
    }

    lm.add(new A("Today", 1L, Boolean.TRUE));
    lm.add(new A("RE: Bandbox Autocomplete Problem", 2L, Boolean.FALSE));
    lm.add(new A("RE: It's not possible to navigate a listbox' ite", 3L, Boolean.FALSE));
    lm.add(new A("RE: FileUpload", 4L, Boolean.FALSE));

    lm.add(new A("Yesterday", 10L, Boolean.TRUE));
    lm.add(new A("RE: Opening more than one new browser window", 11L, Boolean.FALSE));
    lm.add(new A("RE: SelectedItemConverter Question' ite", 12L, Boolean.FALSE));

    lm.add(new A("Last week", 100L, Boolean.TRUE));
    lm.add(new A("RE: Times_Series Chart help", 101L, Boolean.FALSE));
    lm.add(new A("RE: SelectedItemConverter Question", 102L, Boolean.FALSE));

    class VM
    {
        public ListModel getListModel()     { return lm; } 
    }
]]></zscript>

<window id="win" title="Window ZK6 dynamic template" border="normal" width="600px" 
        apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('VM')" >                 
    <listbox model="@bind(vm.listModel) @template(each.isGroup() ? 'group_model' : 'item_model')">
        <listhead>
            <listheader hflex="3" label="Column 1"/>
            <listheader hflex="1" label="Column 2"/>
        </listhead>
        <template name="group_model">
            <listgroup open="true" label="@load(each.label)"/>
        </template>
        <template name="item_model">
            <listitem vflex="1">
                <listcell>
                    <label value="@load(each.getClientName(each.value))"/>
                </listcell>
                <listcell>
                    <label value="@load(each.value)"/>
                </listcell>
            </listitem>
        </template>
    </listbox>
</window>

</zk>

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
2 followers

RSS

Stats

Asked: 2013-07-25 16:01:42 +0800

Seen: 40 times

Last updated: Jul 26 '13

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