Listview might be chancing your List? Use instead an LDM that always fetch
fresh copy of the List...

On Fri, Jun 19, 2015 at 9:03 PM, Ulrich <[email protected]> wrote:

> Want to refresh page and show curently added entry to database. But does
> not
> work. To trap down the reason I've created two applications which are very
> similiar. Both show a java.util.List - on is filled from a database the
> other one immediately from the program (List<String[]>.add()). The second
> one is fine, the first one is in no way dynamic; even Browser refresh does
> not display the new entry; I have to call the whole URL again.
>
> What is wrong with my assumptions. Any hint is appreciated.
>
> brgds
> Ulrich
>
> *Database-Sample:*
> package com.mycompany;
>
> import java.io.IOException;
> import java.util.Date;
> import java.util.List;
>
> import org.apache.wicket.request.mapper.parameter.PageParameters;
> import org.apache.wicket.ajax.AjaxRequestTarget;
> import org.apache.wicket.ajax.markup.html.form.AjaxButton;
> import org.apache.wicket.markup.html.basic.Label;
> import org.apache.wicket.markup.html.form.Form;
> import org.apache.wicket.markup.html.list.ListItem;
> import org.apache.wicket.markup.html.list.ListView;
> import org.apache.wicket.markup.html.WebPage;
> import org.apache.wicket.model.Model;
> import org.apache.wicket.model.PropertyModel;
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> import de.gombers.accounts.dao.mybatis.ListData;
> import de.gombers.accounts.dao.mybatis.ListDataDAO;
>
>
> public class HomePage extends WebPage {
>         private static final Logger LOGGER =
> LoggerFactory.getLogger(HomePage.class);
>         private static final long serialVersionUID = 1L;
>         private List<ListData> dataList;
>
>         public HomePage(final PageParameters parameters) {
>                 super(parameters);
>
>                 Form form = new Form("form");
>
>                 PropertyModel pm = new PropertyModel(this, "dataList");
>                 List<ListData> werte = (List<ListData>) pm.getObject();
>
>
>
>                 final ListView listView =  new ListView("listentries",
> werte ) {
>                         @Override
>                         protected void populateItem(ListItem item) {
>                                 final ListData data=  (ListData)
> item.getModelObject();
>                                 item.add(new Label("mydate", new Model() {
>                                         @Override
>                                         public String getObject() {
>                                                 return
> data.getMyDate().toString();
>                                         }
>                                 }));
>                                 item.add(new Label("mytext", new Model(""){
>                                         @Override
>                                         public String getObject() {
>                                                 return data.getMyText();
>                                         }
>                                 }));
>
>                         }
>                 };
>                 listView.setOutputMarkupId(true);
>                 form.add(listView);
>
>
>                 AjaxButton submit = new AjaxButton("addEntry"){
>                         @Override
>                         protected  void         onSubmit(AjaxRequestTarget
> target, Form<?> form) {
>                                 ListData data = new ListData();
>                                 data.setMyData(new Date());
>                                 data.setMyText("myText");;
>                                 try {
>                                         new
> ListDataDAO().insertNewEntry(data);
>                                 } catch (IOException e) {
>                                         // TODO Auto-generated catch block
>                                         //
>               e.printStackTrace();
>                                 }
>                                 try {
>                                         dataList=new
> ListDataDAO().getAllData();
>                                 } catch (IOException e) {
>                                         LOGGER.error("", e);
>                                 }
>
>                                 target.add(form);
>                         }
>                 };
>
>                 form.add(submit);
>                 add(form);
>         }
>
>         public List<ListData> getDataList() {
>                 try {
>                         dataList=new ListDataDAO().getAllData();
>                         LOGGER.info("ListDataSize2={}", dataList.size());
>                 } catch (IOException e) {
>                         LOGGER.error("", e);
>                 }
>                 return dataList;
>         }
> }
>
> *ListArray-Sample:*
> package com.mycompany;
>
> import java.io.IOException;
> import java.util.ArrayList;
> import java.util.Date;
> import java.util.List;
>
> import org.apache.wicket.request.mapper.parameter.PageParameters;
> import org.apache.wicket.ajax.AjaxRequestTarget;
> import org.apache.wicket.ajax.markup.html.form.AjaxButton;
> import org.apache.wicket.markup.html.basic.Label;
> import org.apache.wicket.markup.html.form.Form;
> import org.apache.wicket.markup.html.list.ListItem;
> import org.apache.wicket.markup.html.list.ListView;
> import org.apache.wicket.markup.html.WebPage;
> import org.apache.wicket.model.Model;
> import org.apache.wicket.model.PropertyModel;
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
>
>
> public class HomePage2 extends WebPage {
>         private static final Logger LOGGER =
> LoggerFactory.getLogger(HomePage.class);
>         private static final long serialVersionUID = 1L;
>         private List<String[]> dataList = new ArrayList() ;
>
>         public HomePage2(final PageParameters parameters) {
>                 super(parameters);
>
>                 Form form = new Form("form");
>                 dataList.add(new String[]{new Date().toString(), "Line no
> 1 "});
>
>                 PropertyModel pm = new PropertyModel(this, "dataList");
>                 List<String[]> werte = (List<String[]>) pm.getObject();
>
>
>                 final ListView listView =  new ListView("listentries",
> werte ) {
>                         @Override
>                         protected void populateItem(ListItem item) {
>                                 final String[] data=  (String[])
> item.getModelObject();
>                                 item.add(new Label("mydate", new Model() {
>                                         @Override
>                                         public String getObject() {
>                                                 return data[0];
>                                         }
>                                 }));
>                                 item.add(new Label("mytext", new Model(""){
>                                         @Override
>                                         public String getObject() {
>                                                 return data[1];
>                                         }
>                                 }));
>
>                         }
>                 };
>                 listView.setOutputMarkupId(true);
>                 form.add(listView);
>
>
>                 AjaxButton submit = new AjaxButton("addEntry"){
>                         @Override
>                         protected  void         onSubmit(AjaxRequestTarget
> target, Form<?> form) {
>                                 LOGGER.info("Submit Button pressed");
>
>                                 String[] data = new String[2];
>                                 data[0]=new Date().toString();
>                                 data[1]=String.format("Line no %s",
> dataList.size());
>                                 dataList.add(data);
>
>                                 target.add(form);
>                         }
>                 };
>
>                 form.add(submit);
>                 add(form);
>         }
>
>         public List<String[]> getDataList() {
>                 return dataList;
>         }
> }
>
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Webpage-does-not-refresh-when-ListView-is-based-on-a-List-supplied-by-a-database-tp4671251.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>


-- 
Regards - Ernesto Reinaldo Barreiro

Reply via email to