0

Macro component property problem

asked 2014-07-09 09:15:29 +0800

kkurt gravatar image kkurt
300 1 2

updated 2014-07-09 10:10:30 +0800

Hi; I am trying to compose my doublelistbox component. Component has two listbox and "add" and "remove" buttons.

There is a problem in renderer. When i set the property 'multiple="true"' for macro component, it does not reflect the property("multiple") inside listboxes. But "checkmark" property reflects...

"multiple" property always "true" in constructor, but when rendering it becames "false".

"checkmark" property value equals in constructor and on rendering time. There is not any problem about "checkmark".

Any idea?

ExListbox.zul(Macro Component)

<hlayout>
<listbox  hflex="1" vflex="true">
    <listhead sizable="true"/>
</listbox>
<vbox spacing="10px" width="24px" pack="center"  align="center" vflex="1">
    <button label="Add"/>
    <button label="Remove"/>
</vbox>
<listbox hflex="1" vflex="true">
    <listhead sizable="true"/>
</listbox>

</hlayout>

ExListbox.java(Macro component controller)

import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.zk.ui.HtmlMacroComponent;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Button;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Listbox;


public class ExListbox extends HtmlMacroComponent {

    private static final long serialVersionUID = 1L;

    @Wire("listbox")
    List<Listbox> listboxList;

    @Wire("button")
    List<Button> buttonList;

    Listbox lb1;
    Listbox lb2;

    boolean secondListboxVisible=false;
    String fields;  
    Collection<Object> model;

    boolean multiple=false;
    boolean checkmark=false;
    boolean paging=false;


    public ExListbox (){
        setMacroURI("/component/ExListbox.zul");
        compose();
    }

    @AfterCompose
    public void afterCompose() {
        //Selectors.wireComponents(view, this, false);
        lb1=listboxList.get(0);
        lb2=listboxList.get(1);
        if (!secondListboxVisible) {
            lb2.detach();
            for (Button button:buttonList) {
                button.detach();
            }
        }
        lb1.setMultiple(multiple);
        lb2.setMultiple(multiple);
        lb1.setCheckmark(checkmark);
        lb2.setCheckmark(checkmark);
    }


    public String getFields() {
        return fields;
    }

    public void setFields(String fields) {
        this.fields = fields;

    }

    public Collection<Object> getModel() {
        return model;
    }

    public void setModel(Collection<Object> model) {


        ExRenderer renderer1;
        ExRenderer renderer2;
        ListModel<Object> listModel1;
        ListModel<Object> listModel2;
        renderer1 = new ExRenderer(lb1);
        renderer2 = new ExRenderer(lb2);
        listModel1=new ListModelList(model);        
        listModel2=new ListModelList(Collections.EMPTY_LIST);
        lb1.setItemRenderer(renderer1);
        lb2.setItemRenderer(renderer2);

        lb1.setModel(listModel1);
        lb2.setModel(listModel2);
        this.model = model;

        lb1.setMultiple(multiple);
        lb2.setMultiple(multiple);
        lb1.setCheckmark(checkmark);
        lb2.setCheckmark(checkmark);

        System.err.println(">>>>?>lb1.isMultiple()="+lb1.isMultiple());

    }

    public boolean isMultiple() {
        return multiple;
    }

    public void setMultiple(boolean multiple) {
        this.multiple = multiple;
    }

    public boolean isCheckmark() {
        return checkmark;
    }

    public void setCheckmark(boolean checkmark) {
        this.checkmark = checkmark;
    }

    public boolean isSecondListboxVisible() {
        return secondListboxVisible;
    }

    public void setSecondListboxVisible(boolean secondListboxVisible) {
        this.secondListboxVisible = secondListboxVisible;
    }



}

ExRenderer.java

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

import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listheader;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;

public class ExRenderer implements ListitemRenderer<Object>,Serializable {

    private static final long serialVersionUID = -1L;

    String fieldsStr;
    List<Listheader> fieldHeaders;
    Listbox lb;

    public  ExRenderer(Listbox lb) {
        this.lb=lb;
        System.out.println(lb+" inRendererConstructor>>>>>lb.isMultiple()="+lb.isMultiple());
        System.out.println(lb+" inRendererConstructor>>>>>lb.isCheckmark()="+lb.isCheckmark());
    }


    @Override
    public void render(Listitem li, Object obj, int index) throws Exception {
        System.out.println(lb+" onRender>>>>>lb.isMultiple()="+lb.isMultiple());                        
        System.out.println(lb+" onRender>>>>>lb.isCheckmark()="+lb.isCheckmark());
    }

}

For testing :

exTest.zul

<window apply="org.zkoss.bind.BindComposer" viewmodel="@id('vm') @init('com.akbank.nkm.component.extendedListbox.ExTest')">

    <exListbox fields="a,b,c" model="@bind(vm.personelList)" checkmark="true" multiple="true" secondListboxVisible="true"/>

</window>

ExTest.java(Test Conrtroller)

import java.util.Collections;
import java.util.List;

import javax.naming.NamingException;

import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.bind.annotation.Init;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.Selectors;

import com.akbank.nkm.dao.sap.PersonelDAOBean;
import com.akbank.nkm.orm.Personel;
import com.akbank.nkm.util.ContextUtil;

public class ExTest {

    PersonelDAOBean personelDAO;

    List<Personel> personelList=Collections.EMPTY_LIST;

    private void initBeans() throws NamingException {
        personelDAO=ContextUtil.find(PersonelDAOBean.class);
    }

    @Init
    public void init(@ContextParam(ContextType.VIEW) Component win) throws Exception {
        initBeans();
        personelList=personelDAO.findAll();

    }

    @AfterCompose
    public void afterCompose(@ContextParam(ContextType.VIEW) Component win) throws NamingException {
        Selectors.wireComponents(win, this, false);
        Selectors.wireEventListeners(win, this);
    }

    public List<Personel> getPersonelList() {
        return personelList;
    }

    public void setPersonelList(List<Personel> personelList) {
        this.personelList = personelList;
    }

}
delete flag offensive retag edit

4 Answers

Sort by ยป oldest newest most voted
0

answered 2014-07-09 14:21:44 +0800

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

I could be wrong understanding, but if you do multiple=true it has to go to the 2 listboxes to?

When yes you can do the following :

<hlayout>
    <listbox  hflex="1" vflex="true"  multiple="${arg.multiple}">    
        <listhead sizable="true"/>
    </listbox>
    <vbox spacing="10px" width="24px" pack="center"  align="center" vflex="1">    
        <button label="Add"/>    
        <button label="Remove"/>
    </vbox>
    <listbox hflex="1" vflex="true">    
        <listhead sizable="true" multiple="${arg.multiple}"/>
    </listbox>
</hlayout>

Greetz chill.

link publish delete flag offensive edit
0

answered 2014-07-09 12:08:33 +0800

neillee gravatar image neillee flag of Taiwan
1692 1 5
https://plus.google.com/u...

When the listbox is driven by a list model, the model will also control the multiple attribute. Therefore, inside your ExListbox.setModel() method, you need to change the attribute setting code to

listModel1.setMultiple(multiple);
listModel2.setMultiple(multiple);
...
lb1.setModel(listModel1);
lb2.setModel(listModel2);
link publish delete flag offensive edit
0

answered 2014-07-09 13:12:33 +0800

kkurt gravatar image kkurt
300 1 2

Ok, thanks but i am using ZK 7.03 and listmodel does not have any method like "setMultiple" ?

link publish delete flag offensive edit
0

answered 2014-07-09 15:04:55 +0800

kkurt gravatar image kkurt
300 1 2

updated 2014-07-09 17:46:52 +0800

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

Ok, i found an answer. I can cast ant set the property like :

((Selectable)lb1.getModel()).setMultiple(multiple);

Thanks...

link publish delete flag offensive edit

Comments

yes see for all implemented interfaces http://www.zkoss.org/javadoc/latest/zk/org/zkoss/zul/ListModelList.html

cor3000 ( 2014-07-10 02:25:16 +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: 2014-07-09 09:15:29 +0800

Seen: 25 times

Last updated: Jul 09 '14

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