在ZK中摆脱形式的问题

时间:2014-10-22 05:36:30

标签: hibernate zk

我目前有一段代码,我试图弄清楚自己:

  <groupbox id="mygrp">
    <caption label="Dish" />
    Title:
    <textbox id="dishTitle" cols="25" value="@bind(vm.selectedDish.title)" />
    <div>
      Price:
      <decimalbox id="dishPrice2" format="#,###.##" cols="10" hflex="min" value="@bind(vm.selectedDish.price)" />
    </div>
    <hlayout>
      <button id="add" label="Add" onClick="@command('add') @validator('eventValidator.DishValidator')" />
      <button id="update" label="Update" onClick="@command('update') @validator('eventValidator.DishValidator')"/>
      <button id="delete" label="Delete" onClick="@command('delete') @validator('eventValidator.DishValidator')"/>
    </hlayout>
  </groupbox>

我得到的错误是

 org.hibernate.PropertyValueException: not-null property references a null or transient value : model.Dish.price 

正常运行的代码是:

  <groupbox id="mygrp" form="@id('dish') @load(vm.selectedDish) @save(vm.selectedDish, before='update') @save(vm.newDish, before='add')">
    <caption label=" Dish " />
  Title:
  <textbox id="dishTitle" cols="25" value="@bind(dish.title)" />
  <div>
    Price:
    <decimalbox id="dishPrice2" format="#,###.##" cols="10" hflex="min" value="@bind(dish.price)" />
  </div>
  <hlayout>
    <button id="add" label="Add" onClick="@command('add') @validator('eventValidator.DishValidator')" />
    <button id="update" label="Update" onClick="@command('update') @validator('eventValidator.DishValidator')" />
    <button id="delete" label="Delete" onClick="@command('delete') @validator('eventValidator.DishValidator')" />
  </hlayout>

  </groupbox>

我无法理解如何在不丢失@load和@save的情况下摆脱形式

1 个答案:

答案 0 :(得分:1)

答案是:

  <groupbox id="mygrp">
    <caption label=" Dish " />
  Title:
  <textbox id="dishTitle" cols="25" value="@load(vm.selectedDish.title) @save(vm.selectedDish.title, before='update') @save(vm.newDish.title, before='add')" />
  <div>
    Price:
    <decimalbox id="dishPrice2" format="#,###.##" cols="10" hflex="min" value="@load(vm.selectedDish.price) @save(vm.selectedDish.price, before='update') @save(vm.newDish.price, before='add')" />
  </div>
  <hlayout>
    <button id="add" label="Add" onClick="@command('add') @validator('eventValidator.DishValidator')" />
    <button id="update" label="Update" onClick="@command('update') @validator('eventValidator.DishValidator')" />
    <button id="delete" label="Delete" onClick="@command('delete') @validator('eventValidator.DishValidator')" />
  </hlayout>

  </groupbox>

最后找到了一些关于属性绑定的正确文档