Re: Keep the state or value of a DropDownChoice and TextField both inside a ListView
Thanks Ernesto for your help Bruno Moura 2013/5/5 Ernesto Reinaldo Barreiro > From javadoc of ListView > > * > * WARNING: though you can nest ListViews within Forms, > you HAVE to set the > * setReuseItems property to true in order to have validation work > properly. By default, > * setReuseItems is false, which has the effect that ListView replaces all > child components by new > * instances. The idea behind this is that you always render the fresh > data, and as people usually > * use ListViews for displaying read-only lists (at least, that's what we > think), this is good > * default behavior. > * However, as the components are replaced before the rendering starts, the > search for specific > * messages for these components fails as they are replaced with other > instances. Another problem is > * that 'wrong' user input is kept as (temporary) instance data of the > components. As these > * components are replaced by new ones, your user will never see the wrong > data when setReuseItems > * is false. > * > > > > On Mon, May 6, 2013 at 5:32 AM, Bruno Moura wrote: > > > 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. > > > > The following pictures show what's happen before and after add a new > > ListView item: > > > > [image: Imagem inline 1] > > > > And after Add a new item: > > > > [image: Imagem inline 1] > > > > I'm implemented the 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/ HH:mm:ss") > > } else > > result = workSheet.endDate.toString("dd/MM/ HH:mm:ss") > > return result > > } > > })) > > > > def onClick() {} > > } > > > > > > The only values preserved are the values of the labels. > > > > Please, someone could help me, thanks > > > > > > > > Bera > > > > > > -- > Regards - Ernesto Reinaldo Barreiro >
Re: Keep the state or value of a DropDownChoice and TextField both inside a ListView
>From javadoc of ListView * * WARNING: though you can nest ListViews within Forms, you HAVE to set the * setReuseItems property to true in order to have validation work properly. By default, * setReuseItems is false, which has the effect that ListView replaces all child components by new * instances. The idea behind this is that you always render the fresh data, and as people usually * use ListViews for displaying read-only lists (at least, that's what we think), this is good * default behavior. * However, as the components are replaced before the rendering starts, the search for specific * messages for these components fails as they are replaced with other instances. Another problem is * that 'wrong' user input is kept as (temporary) instance data of the components. As these * components are replaced by new ones, your user will never see the wrong data when setReuseItems * is false. * On Mon, May 6, 2013 at 5:32 AM, Bruno Moura wrote: > 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. > > The following pictures show what's happen before and after add a new > ListView item: > > [image: Imagem inline 1] > > And after Add a new item: > > [image: Imagem inline 1] > > I'm implemented the 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/ HH:mm:ss") > } else > result = workSheet.endDate.toString("dd/MM/ HH:mm:ss") > return result > } > })) > > def onClick() {} > } > > > The only values preserved are the values of the labels. > > Please, someone could help me, thanks > > > > Bera > -- Regards - Ernesto Reinaldo Barreiro
Keep the state or value of a DropDownChoice and TextField both inside a ListView
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. The following pictures show what's happen before and after add a new ListView item: [image: Imagem inline 1] And after Add a new item: [image: Imagem inline 1] I'm implemented the 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/ HH:mm:ss") } else result = workSheet.endDate.toString("dd/MM/ HH:mm:ss") return result } })) def onClick() {} } The only values preserved are the values of the labels. Please, someone could help me, thanks Bera