scala - Keep the state or value of a DropDownChoice and TextField both inside a ListView -


i have implemented listview , every time new item added in listview values inserted in textfield , selected in dropdownchoice lost.

the following pictures show what's happen before , after add new listview item:

listviewbefore

and after add new item:

listviewafter

i'm implemented code bellow:

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

the values preserved values of labels.

please, me,

after add new item list refresh it, not saved values lost. in case following:

first, save data on change (onblur/onchange or button 'save').

second, bind description , customerselection on populating, so:

new textfield("description", new propertymodel(obj, "description")) new dropdownchoice("customerselection", new propertymodel(obj, "customer"), listcustomer, new choicerenderer[customer]("id"))) 

Comments