0

Trouble with the use of zk Live Demo - Data Filter

asked 2013-06-25 10:17:42 +0800

RobinGeissmann gravatar image RobinGeissmann
3 1

Hi there

I'm trying to get the Data Filter Demo running in my app. Slightly modified of course. I am relatively new to the whole zkoss & Frontend Java thing.

If I run the Page I get the following error: org.zkoss.zk.ui.UiException: Property 'filter' not found on type step.library.controller.KeywordFilterViewModel

I am not quite sure what it tries to tell me there, but I am sure that "filter" is around in KeywordFilterViewModel. Could you point out the mistake I am doing here, or what I am understanding wrong?

Thank you in advance

This is my code of the KeywordFilterViewModel & the page, I can post the other involved classes if there's a need for that;

<?page title="Auto Generated index.zul"?>
<tabbox vflex="1" hflex="1">
    <tabs>
        <tab label="test" />
        <tab label="" />
    </tabs>
    <tabpanels>
        <tabpanel vflex="1" hflex="1">
            <borderlayout vflex="1" hflex="1" >
                <west size="30%" border="0">
                    <div vflex="1" hflex="1" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('step.library.controller.KeywordFilterViewModel')">
                        <grid vflex="1" hflex="1">
                            <auxhead>
                                <auxheader>
                                    <bandbox autodrop="false" hflex="1" value="@bind(vm.filter.id)" onChange="@command('changeFilter')">
                                    </bandbox>
                                </auxheader>
                            </auxhead>
                            <columns>
                                <column>
                                    ID
                                </column>
                            </columns>
                            <template name="model">
                                <row>
                                    <label value="@load(each.id)"/>
                                </row>
                            </template>
                        </grid>
                    </div>  
                </west>
                <center border="0">
                    bla
                </center>
            </borderlayout> 
        </tabpanel>
        <tabpanel></tabpanel>
    </tabpanels>
</tabbox>


package step.library.controller;

import java.util.List;

import org.zkoss.zul.ListModel;
import org.zkoss.zul.ListModelList;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.NotifyChange;

import step.library.data.Keyword;
import step.library.data.KeywordData;
import step.library.controller.KeywordFilter;

public class KeywordFilterViewModel {
    private KeywordFilter filter = new KeywordFilter();
    List<Keyword> currentKeyword = KeywordData.getAllKeywords();

    public KeywordFilter getKeywordFilter(){
        return filter;
    }

    public ListModel<Keyword> getKeywordModel(){
        return new ListModelList<Keyword>(currentKeyword);
    }

    @Command
    @NotifyChange({"foodModel"})
    public void changeFilter(){
        currentKeyword = KeywordData.getFilteredKeywords(filter);
    }
}
delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2013-06-25 13:03:29 +0800

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

updated 2013-06-25 13:09:53 +0800

You can check here zk-listbox-data-filter-demoOR See below Sample ...Its a Basic demo... ZUL FIle

<?page title="Auto Generated index.zul"?>
<window apply="org.zkoss.bind.BindComposer"
    viewModel="@id('vm') @init('demo.listbox.FilterViewModel')">


    <listbox model="@load(vm.modelList)">

        <auxhead sclass="category-center">
            <auxheader colspan="1">
                <textbox instant="true" width="100px"
                    value="@bind(vm.people.name)" onChange="@command('changeFilter')" />
            </auxheader>


        </auxhead>
        <listhead>
            <listheader label="Name"></listheader>
            <listheader label="Age"></listheader>
            <listheader label="Id"></listheader>
        </listhead>
        <template name="model" var="person">
            <listitem>

                <listcell>
                    <label value="@load(person.name)" />
                </listcell>
                <listcell>
                    <label value="@load(person.age)" />
                </listcell>
                <listcell>
                    <label value="@load(person.id)" />
                </listcell>
            </listitem>
        </template>




    </listbox>
</window>

Java Code or ViewModel

package demo.listbox;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.ListModelList;

public class FilterViewModel {

    private List myPersonList;
    private Person people = new Person();
    private ListModel<Person> modelList;

    @AfterCompose
    public void afterCompose() {
        myPersonList = new ArrayList<Person>();

        myPersonList.add(new Person("Hariom", 1, "om1"));
        myPersonList.add(new Person("Narayan", 2, "Hariom1"));
        myPersonList.add(new Person("Shiv", 3, "shiv"));
        myPersonList.add(new Person("Ram", 4, "Maa"));
        myPersonList.add(new Person("Krishna", 5, "Durga"));
        modelList = new ListModelList<Person>(myPersonList);
    }

    @Command
    @NotifyChange("modelList")
    public void changeFilter() {
        List myPersonList1 = getFilterPersons(people);
        modelList = new ListModelList<Person>(myPersonList1);
    }

    public List<Person> getFilterPersons(Person personObj) {
        List<Person> personsList = new ArrayList<Person>();
        String name = null;
        Integer age = null;
        String id = null;
        if (personObj!=null && personObj.getName() != null)
            name = personObj.getName().toLowerCase();
        if (personObj!=null && personObj.getAge() != null)
            age = personObj.getAge();
        if (personObj!=null && personObj.getId() != null)
            id = personObj.getId().toLowerCase();

        for (Iterator<Person> i = myPersonList.iterator(); i.hasNext();) {
            Person tmp = i.next();

            if (tmp.getName().toLowerCase().contains(name) && !name.trim().isEmpty() ) {
                personsList.add(tmp);
            }

        }
        if(personsList.size()>0)
        return personsList;
        else
            return myPersonList;
    }

    public class Person {
        String name;
        Integer age;
        String id;

        public String getName() {
            return name;
        }

        public Integer getAge() {
            return age;
        }

        public String getId() {
            return id;
        }

        public void setName(String name) {
            this.name = name;
        }

        public void setAge(Integer age) {
            this.age = age;
        }

        public void setId(String id) {
            this.id = id;
        }

        public Person() {

        }

        public Person(String name, Integer age, String id) {
            super();
            this.name = name;
            this.age = age;
            this.id = id;
        }

    }

    public List getMyPersonList() {
        return myPersonList;
    }

    public Person getPeople() {
        return people;
    }

    public void setMyPersonList(List myPersonList) {
        this.myPersonList = myPersonList;
    }

    public void setPeople(Person people) {
        this.people = people;
    }

    public ListModel<Person> getModelList() {
        return modelList;
    }

    public void setModelList(ListModel<Person> modelList) {
        this.modelList = modelList;
    }

}
link publish delete flag offensive edit
0

answered 2021-03-02 18:28:49 +0800

cla gravatar image cla
1

Hi sjoshi, in your code how do i use the filter by name, age and id? and not just by name like in your demo? I tried like that but I have a NullPointer error:

for (Iterator<Person> i = myPersonList.iterator(); i.hasNext();) {
        Person tmp = i.next();

        if (tmp.getName().toLowerCase().contains(name) && !name.trim().isEmpty() ) {
            personsList.add(tmp);
        }

        if (tmp.getAge().toLowerCase().contains(age) && !age.trim().isEmpty() ) {
            personsList.add(tmp);
        }
}
link publish delete flag offensive edit

Comments

I assume you didn't post the correct code, since this should not even compile ... tmp.getAge() returns an Integer which doesn't have a toLowerCase() method. Can you provide the compiling code you're running with and the line number where the exception happens?

cor3000 ( 2021-03-03 16:26:08 +0800 )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: 2013-06-25 10:17:42 +0800

Seen: 41 times

Last updated: Mar 02 '21

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