You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Ulrich <Fo...@gombers.de> on 2015/06/19 21:03:41 UTC

Webpage does not refresh when ListView is based on a List supplied by a database

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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Webpage does not refresh when ListView is based on a List supplied by a database

Posted by Ulrich <Fo...@gombers.de>.
@Sebastien,
thanks - works. I had started this way, but didn't get the ListView becoming
instantiated. Trying again now worked fine.
Nevertheless I still can't tell why the both of the approaches react
different; I had implemented it as far as I can see alike.


--
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-tp4671251p4671267.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Webpage does not refresh when ListView is based on a List supplied by a database

Posted by Sebastien <se...@gmail.com>.
Hi,

> PropertyModel pm = new PropertyModel(this, "dataList");
> List<ListData> werte = (List<ListData>) pm.getObject();
> final ListView listView =  new ListView("listentries", werte )

You need to pass a model to the list view:
final ListView listView =  new ListView("listentries", new
PropertyModel<List<ListData>(this, "dataList"))

Also please note that you should avoid unwraping a model (calling
#getObject) in the constructor...

Hope this helps,
Sebastien.


On Fri, Jun 19, 2015 at 9:03 PM, Ulrich <Fo...@gombers.de> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Webpage does not refresh when ListView is based on a List supplied by a database

Posted by Sebastien <se...@gmail.com>.
Hi Ulrich,

If not already done, you should read the wicket free guide, in particular
the model section:
http://ci.apache.org/projects/wicket/guide/6.x/guide/single.html#modelsforms_1

The PropertyModel paragraph will answer your question...

Happy reading & best regards,
Sebastien.


On Sat, Jun 20, 2015 at 4:31 PM, Ulrich <Fo...@gombers.de> wrote:

> @Ernesto,
> I understand, that the idea of the LoadableDetachableModule is to get rid
> of
> the storage occupied by the list to avoid an overhead of serialization. To
> get sort of dynamics it mus be nested with a PropertyModel, isn't it?
> I will give it a try tomorrow.
>
> --
> 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-tp4671251p4671268.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Webpage does not refresh when ListView is based on a List supplied by a database

Posted by Ulrich <Fo...@gombers.de>.
@Ernesto,
I understand, that the idea of the LoadableDetachableModule is to get rid of
the storage occupied by the list to avoid an overhead of serialization. To
get sort of dynamics it mus be nested with a PropertyModel, isn't it?
I will give it a try tomorrow.

--
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-tp4671251p4671268.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Webpage does not refresh when ListView is based on a List supplied by a database

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
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 <Fo...@gombers.de> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Regards - Ernesto Reinaldo Barreiro