为了避免浪费你的时间,这是apache wicket和scala开发人员的问题,谢谢。
我已经创建了一个带有populateList方法的listView,它根据下图中的每一行填充客户会议列表和相应的经理:
这里有两个问题:
因此,值仅保留在标签中,实际链接中。让我展示一下代码:
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>
我认为需要一个Object,类似于LinkDate,用于处理和存储Manager DropDownChoice以及textField或AjaxEditableLabel Detail的值,但是我很难实现它们。
感谢有人帮助我或向我提供有关
的信息答案 0 :(得分:1)
尝试替换这些行
item.add(new DropDownChoice("managerSelection", listManagers,new ChoiceRenderer[Manager]("name")))
item.add(new TextField("detail"))
类似于:
val managerSelectionCurrent = new PropertyModel(customer, "manager")
val managerSelection = new DropDownChoice[Manager]("managerSelection", managerSelectionCurrent, listManagers,new ChoiceRenderer[Manager]("name")) {
protected override def wantOnSelectionChangedNotifications: Boolean = {
true
}
protected override def onSelectionChanged(newSelection: Manager) {
// save changes
}
}
item.add(managerSelection)
val detail = new TextField("detail", new PropertyModel(customer, "details"))
detail.add(new AjaxFormComponentUpdatingBehavior(("keyup")) {
protected def onUpdate(target: AjaxRequestTarget) {
// save changes
}
protected override def updateAjaxAttributes(attributes: AjaxRequestAttributes) {
attributes.setThrottlingSettings(new ThrottlingSettings("thr", Duration.milliseconds(800)))
super.updateAjaxAttributes(attributes)
}
})
item.add(detail)