2013-05-14 56 views
1

我有問題訪問我的ViewModel內的對象的屬性。我沒有收到目的地錯誤。任何指針?謝謝。無法加載/保存ViewModel屬性的屬性

錯誤消息:

目標不可達,「TOTO」返回null

基本上,當我填寫文本框,並在窗口中點擊某個地方,我會得到錯誤。當我使用其他ViewModel的屬性(這是一個字符串)時,它可以像我期望的那樣工作。

設置:

我使用JBoss工作室。該應用程序在JBoss AS 7上運行。基本上,我按照本指南http://books.zkoss.org/wiki/ZK_Installation_Guide/Quick_Start/Create_and_Run_Your_First_ZK_Application_with_Eclipse_and_Maven創建我的項目。

祖爾文件:

<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; 
    } 


} 

Person類:

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; 
     } 


} 
+0

我剛剛測試了您的代碼,它對我來說工作得很好。可以請您分享更多詳細信息 – 2013-05-14 05:53:00

+0

我使用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創建我的項目。告訴我你是否需要更多信息。謝謝。 – wmfairuz 2013-05-14 06:54:11

+0

基本上,當我填入文本框並單擊窗口中的某個位置時,我會收到錯誤消息。當我使用ViewModel的屬性(它是一個字符串)時,它按我的預期工作。 – wmfairuz 2013-05-14 06:55:26

回答

2

如果您將檢查您的視圖模型,你已經寫了這個代碼private Person toto;,並與方法編號:get/set w ^如你所知toto=null所以要解決這個問題,你必須改變你的代碼是這樣

private Person toto = new Person(); 

這將解決您的問題。

+0

謝謝。這樣可行。 – wmfairuz 2013-05-14 07:21:28