为了避免浪费您的时间,这是 apache wicket 和 scala 开发人员的问题,谢谢。
我创建了一个带有方法 populateList 的 listView,它根据下图填充了与负责每行的相应经理的客户会议列表:
这里有两个问题:
- 创建新项目时,仅保留字段(标签)dateBegin 和 dateEnd 以及先前分配的值,我丢失了ListItem 最后一行中Manager DropDownChoice和Detail TextField的值。
- 在更改从Detail TextField退出后的DropDownChoice后,需要使用从每个字段中选择的相应值更新模型。
因此,这些值仅保留用于标签,实际上是链接。让我展示一下代码:
add(new ListView[Meetings]("listMeetings", listData) {
override protected def onBeforeRender() {
periodTotal = new Period()
super.onBeforeRender()
}
// for populating the listView
def populateItem(item: ListItem[customer]) = {
var customer = item.getModelObject()
item.add(new LinkDate("beginDate", customer))
item.add(new LinkDate("endDate", customer))
val listManagers: java.util.List[Manager] = managerDAO.listManagers
item.add(new DropDownChoice("managerSelection", listManagers,new ChoiceRenderer[Manager]("name")))
item.add(new TextField("detail"))
/*
* I tried to use the code bellow but it's cause a markups errors too.
* Only the code above display the components without errors.
*/
//val managerSelection = new LinkManager("managerSelection",customer)
//item.add(managerSelection)
//item.add(new LinkDetail("detail", customer))
var period = new Period(customer.beginDate, customer.endDate.get)
item.add(new Label("total", period.toString(getFormatter())))
item.add(new LinkEdit("edit", customer))
}})
下面的函数适用于日期值和编辑行的相应字段:
private class LinkDate(id: String, customer: Customer) extends Link[String](id) {
setEnabled(false)
add(new Label("label", new Model[String]() {
override def getObject(): String = {
var result = ""
if (id == "beginDate") {
result = customer.beginDate.toString("dd/MM/YYYY HH:mm:ss")
}
if (id == "endDate") {
result = customer.endDate.get.toString("dd/MM/YYYY HH:mm:ss")
}
return result
}
}))
// ... doing other stuff
}
private class LinkEdit(id: String, customer: Customer) extends Link[String](id) {
add(new Label("label", new Model[String]() {
override def getObject: String = "edit"
}));
// ... doing other stuff
}
但是对于 DropDown 和 TextField 我尝试做同样的事情,但我失败了:
// Doesn't work
private class LinkManager(id: String, customer: Customer) extends Link[String](id) {
val listManagers: java.util.List[Manager] = managerDAO.listManagers
add(new DropDownChoice("managerSelection", listManagers,new ChoiceRenderer[Manager]("name") {
def wantOnSelectionChangedNotifications() = {
true;
}
def onSelectionChanged(managerSelection: Manager): String = {
// saving model
})
}
}))
// ... doing other stuff
}
// Doesn't work
// Also here I tried to change textFiled for a inline-ajax Editable label
// And I need the behaviour to change model imadiately after change value
private class LinkDetail(id: String, customer: Customer) extends Link[String](id) {
add(new AjaxEditableLabel("detail", new Model[String]() {
override def getObject(): String = {
// ... doing other stuff
}
}))
}
对应的标记如下所示:
<TR wicket:id="listCustomersMeetings">
<TD><a wicket:id="beginDate"><span wicket:id="label"></span></a></TD>
<TD><a wicket:id="endDate"><span wicket:id="label"></span></a></TD>
<TD>
<SELECT wicket:id="managerSelection" name="id"></SELECT>
<BR>
</TD>
<TD><INPUT wicket:id="detail" type="text" name="obs" value="_"/></TD>
<TD wicket:id="total"></TD>
<TD><a wicket:id="edit"><span wicket:id="label" style="text-align: center"></span></a></TD>
</TR>
我认为需要一个类似于 LinkDate 的对象来处理和存储 Manager DropDownChoice 和 textField 或 AjaxEditableLabel Detail 的值,但我在实现它们时遇到了麻烦。
感谢有人可以帮助我或给我有关信息