0

当我试图将DoubleboxDecimalbox等 ZK 组件与字符串 变量绑定时

package com.viewmodel;

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

import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.zk.ui.Component;

import com.binding.BindComponent;

public class BindingViewModel {
    BindComponent compo = null;
    private List<BindComponent> dataList;

    @AfterCompose
    public void afterCompose(@ContextParam(ContextType.VIEW) Component view){
        dataList = new ArrayList<BindComponent>();
        compo = new BindComponent();
        compo.setDecimalbox("12.67");
        compo.setTextbox("hariom");
        compo.setDoublebox("123");
        compo.setIntbox(12);
        dataList.add(compo);

    }

    public BindComponent getCompo() {
        return compo;
    }
    public void setCompo(BindComponent compo) {
        this.compo = compo;
    }
    public List<BindComponent> getDataList() {
        return dataList;
    }
    public void setDataList(List<BindComponent> dataList) {
        this.dataList = dataList;
    }


}

ZUl 页面..

<?page title="Auto Generated index.zul"?>
<window title="Hello World!!" apply="org.zkoss.bind.BindComposer"
    border="normal" width="200px"
    viewModel="@id('vm') @init('com.viewmodel.BindingViewModel')">

    <label value="You are using: ${desktop.webApp.version}" />

    <listbox model="@bind(vm.dataList)">
        <listhead>
            <listheader value="Textbox"></listheader>
            <listheader value="DoubleBox"></listheader>
            <listheader value="IntBox"></listheader>
            <listheader value="DecimalBox"></listheader>

        </listhead>
        <template name="model" var="mymodel">
            <listitem>
                <listcell>
                    <textbox value="@bind(mymodel.textbox)"></textbox>
                </listcell>
                <listcell>
                    <doublebox value="@bind(mymodel.doublebox)"></doublebox>
                </listcell>
                <listcell>
                    <intbox value="@bind(mymodel.intbox)"></intbox>
                </listcell>
                <listcell>
                    <decimalbox value="@bind(mymodel.decimalbox)"></decimalbox>
                </listcell>
            </listitem>
        </template>
    </listbox>
</window>

还有豆类......

public class BindComponent {
    private String textbox;
    private int intbox;
    private String doublebox;
    private String decimalbox;
    public String getTextbox() {
        return textbox;
    }
    public void setTextbox(String textbox) {
        this.textbox = textbox;
    }
    public int getIntbox() {
        return intbox;
    }
    public void setIntbox(int intbox) {
        this.intbox = intbox;
    }
    public String getDoublebox() {
        return doublebox;
    }
    public void setDoublebox(String doublebox) {
        this.doublebox = doublebox;
    }
    public String getDecimalbox() {
        return decimalbox;
    }
    public void setDecimalbox(String decimalbox) {
        this.decimalbox = decimalbox;
    }



}

现在的问题是,当我要更改 zul 页面中的值时,不会调用 set 方法,因为我正在将 zul 值与字符串变量绑定。谁能告诉我代码有什么问题?

4

1 回答 1

0

我认为问题是Decimalbox#getValue()返回一个 解决方案应该是BigDecimal

public void setDecimalbox(BigDecimal decimalbox) {
    this.decimalbox = decimalbox != null ? decimalbox.toString() : this.decimalbox;
}

而对于Doublebox

public void setDoublebox(Double doublebox) {
    this.doublebox = doublebox != null ? doublebox.toString : this.doublebox;
}
于 2013-05-28T05:40:42.100 回答