Note that there are some explanatory texts on larger screens.

plurals
  1. POKeep the state or value of a DropDownChoice and TextField both inside a ListView
    text
    copied!<p>I have implemented a listView and every time that a new item is added in this ListView the values inserted in the textField and selected in a DropDownChoice are lost.</p> <p>The following pictures show what's happen before and after add a new ListView item:</p> <p><img src="https://i.stack.imgur.com/E3MQv.png" alt="ListViewBefore"></p> <p>And after Add a new item:</p> <p><img src="https://i.stack.imgur.com/H2qBd.png" alt="ListViewAfter"></p> <p>I'm implemented the code bellow:</p> <pre><code> 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() {} } </code></pre> <p>The only values preserved are the values of the labels. </p> <p>Please, someone could help me, thanks </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload