1

ViewModel 内のオブジェクトのプロパティへのアクセスに問題があります。未到達宛先エラーが発生しました。任意のポインタをお願いします? ありがとう。

エラーメッセージ:

ターゲットに到達できません。'toto' が null を返しました

基本的に、テキストボックスに入力してウィンドウ内のどこかをクリックするとエラーが発生します。他の ViewModel のプロパティ (文字列) を使用すると、期待どおりに動作します。

設定:

JBoss Studio を使用しています。アプリケーションは JBoss AS 7 で実行されています。基本的に、このガイドhttp://books.zkoss.org/wiki/ZK_Installation_Guide/Quick_Start/Create_and_Run_Your_First_ZK_Application_with_Eclipse_and_Mavenに従ってプロジェクトを作成します。

Zul ファイル:

<window apply="org.zkoss.bind.BindComposer"
        viewModel="@id('vm') @init('com.maylab.fault.TicketsViewModel')"
        title="Trouble Ticket" width="600px" border="normal">
    <hbox style="margin-top:20px">
        <textbox value="@save(vm.toto.name)"></textbox>
        <label value="@load(vm.toto.name)"></label>
    </hbox> 
</window>

ビューモデル:

package com.maylab.fault;

import org.zkoss.bind.annotation.*;

import com.maylab.fault.Person;

public class TicketsViewModel {

    private String ticket;
    private String test;
    private Person toto;

    public Person getToto() {
        return toto;
    }

    public void setToto(Person toto) {
        this.toto = toto;
    }

    public String getTest() {
        return test;
    }

    public void setTest(String test) {
        this.test = test;
    }

    public String getTicket() {
        return ticket;
    }

    public void setTicket(String ticket) {
        this.ticket = ticket;
    }


}

人物クラス:

package com.maylab.fault;

public class Person {

        private String name;

        public Person(){

        }

        public Person(String name){
            this.name = name;
        }

        public String getName() {
            return name;
        }

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


}
4

1 に答える 1

2

ビューモデルを確認する場合は、このコード private Person toto;を記述しており、get/setご存知のtoto=nullようにメソッドを使用しているため、この問題を解決するには、コードを次のように変更する必要があります

private Person toto = new Person();

これで問題が解決します。

于 2013-05-14T07:02:35.673 に答える