使用组合框和可编辑标签填充 Listitem 并按行保留每个对象的状态 [英] Populate Listitem with comboboxes and editables labes and preserve the state of each object in lines

查看:31
本文介绍了使用组合框和可编辑标签填充 Listitem 并按行保留每个对象的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了避免浪费您的时间,这是 apache wicket 和 Scala 开发人员的问题,谢谢.

For avoid waste your time, this is a question for apache wicket and scala developers, thanks.

我创建了一个带有 populateList 方法的 listView,它根据下图填充了与负责每一行的相应经理的客户会议列表:

I have created a listView with method populateList, that fills a list of customers meetings with the respective manager responsible for each line according the figure bellow:

这里有两个问题:

  1. 创建新项目时,只有字段(标签)dateBegin 和dateEnd 与以前分配的值一起保留,我丢失了Manager DropDownChoiceDetail 的值TextField 在 ListItem 的最后一行.
  2. 更改后Detail TextFieldafter 退出的DropDownChoice 需要更新模型 具有从每个字段中选择的相应值.
  1. When a new new item is created, only the fields (labels) dateBegin and dateEnd are preserved with previous assigned values, I lost the values of Manager DropDownChoice and the Detail TextField in last line of the ListItem.
  2. After change the DropDownChoice of after exit from the Detail TextField is needed update the model with the respective value have chosen from each field.

因此这些值仅用于标签,实际上是链接.让我展示一下代码:

So the values are kept only for labels, in truth links. Let me show the code:

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))
}})

下面的函数适用于日期值和编辑行的相应字段:

The functions bellow work fine for date value and for edit a respective fields of the line:

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,我尝试做同样的事情,但我失败了:

But for DropDown and TextField I tried to do the same and I failed strongly:

  // 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 的值,但我在实现它们时遇到了麻烦.

I think that is needed a Object, similar to LinkDate, to deal and store the values for Manager DropDownChoice and for the textField or AjaxEditableLabel Detail, but I got in trouble to implement them.

感谢有人可以帮助我或向我提供有关

Thanks for someone that could help me or give me information about

推荐答案

尝试替换这些行

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)

这篇关于使用组合框和可编辑标签填充 Listitem 并按行保留每个对象的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆