我已经实现了一个 listView,每次在这个 ListView 中添加一个新项目时,插入到 textField 中并在 DropDownChoice 中选择的值都会丢失。
下图显示了添加新 ListView 项之前和之后发生的情况:
在添加新项目之后:
我实现了下面的代码:
var listData = workSheetDAO.listWorkSheetUser(selectedUser, beginDate, endDate)
var lbPeriodTotal = new Label("periodTotal")
lbPeriodTotal.setOutputMarkupId(true)
add(lbPeriodTotal)
add(new ListView[WorkSheet]("listWorkSheet", listData) {
override protected def onBeforeRender() {
super.onBeforeRender()
}
def populateItem(item: ListItem[WorkSheet]) = {
var workSheet = item.getModelObject()
item.add(new LinkDate("initDate", workSheet, 1))
item.add(new LinkDate("endDate", workSheet, 1))
item.add(new TextField("description"))
val listCustomer: java.util.List[Customer] = customerDAO.listCustomers
item.add(new DropDownChoice("customerSelection", listCustomer, new ChoiceRenderer[Customer]("id")))
if (workSheet.endDate == None) {
item.add(new Label("total", ""))
} else {
var period = new Period(workSheet.initDate, workSheet.endDate.get)
periodTotal = periodTotal.plus(period)
lbPeriodTotal.setDefaultModel(new Model(periodTotal.toPeriod().normalizedStandard().toString(getFormatter())))
period = period.normalizedStandard()
item.add(new Label("total", period.toString(getFormatter())))
}
}
}
private class LinkDate(id: String, workSheet: WorkSheet, type: Int) extends Link[String](id) {
setEnabled(false)
add(new Label("label", new Model[String]() {
override def getObject(): String = {
var result = ""
if (type == 1) {
result = workSheet.initDate.toString("dd/MM/YYYY HH:mm:ss")
} else
result = workSheet.endDate.toString("dd/MM/YYYY HH:mm:ss")
return result
}
}))
def onClick() {}
}
唯一保留的值是标签的值。
拜托,有人可以帮助我,谢谢