2013-05-14 57 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