You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "wmike1987@gmail.com" <wm...@gmail.com> on 2011/06/07 23:18:43 UTC

adding items dynamically to ListView

I'm trying to add items to a listView when a user clicks a button. I have a
propertyModel backing my ListView. In the onClick(), I do:

AjaxLink newIncButton = new AjaxLink("newIncButton"){
	@Override
	public void onClick(AjaxRequestTarget target) {
             List list = new ArrayList(bean.getIncList());
	       Incident inc = new Incident();
	       inc.setAction("action");
	       inc.setDescription("whatever description");
	       list.add(0, inc);
	       bean.setIncList(list);
             }
}

the variable "bean" is the object which backs the propertyModel.

The ListView doesn't appear to be refreshing with the new item I put in the
list.


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/adding-items-dynamically-to-ListView-tp3580840p3580840.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: adding items dynamically to ListView

Posted by "wmike1987@gmail.com" <wm...@gmail.com>.
Just resolved the issue. The problem was that I wasnt setting
"container.setOutputMarkupId(true);" before I initially added the container
to the page. I was setting it when the user clicked a button, which always
occurred after the container was initially added. 

My original flow was something like this:



WicketPanel class {
   ...
   instantiate container

   ajax onClick() {
      container.setOutputMarkupId(true);
      target.addComponent(container)
   }

   add(container)
}


It needs to be like this:



WicketPanel class {
   ...
   instantiate container
   container.setOutputMarkupId(true);

   ajax onClick() {
      target.addComponent(container)
   }

   add(container)
}


Makes sense. Thanks for all the help


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/adding-items-dynamically-to-ListView-tp3580840p3582682.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: adding items dynamically to ListView

Posted by "wmike1987@gmail.com" <wm...@gmail.com>.
Here is my bean class, followed by a panel class where I set up the
PropertyModel and the ListView, followed lastly by the panel's markup

BEAN:
public class IncidentListBean implements Serializable
{
	List<Incident> incList;
	public IncidentListBean() {
		incList = new ArrayList();
	}
	
	public List getIncList() {
		return incList;
	}
	
	public void setIncList(List list) {
		incList = list;
	}
}


PANEL:
public class IncidentPanel extends Panel
{
	transient List<Incident> incList = DashboardServiceAccessor.get("SELECT *
FROM MY_DB");
	IncidentListBean bean = new IncidentListBean();
	PropertyModel propMod;
	ListView listView;
	WebMarkupContainer container;
	
	public IncidentPanel(String id) {
		super(id);
		
		//set up the property model that will represent the listView below
		bean.setIncList(incList);
		propMod = new PropertyModel(bean, "incList");
		container = new WebMarkupContainer("repeaterContainer");
		
                         //ListView
                         listView = new ListView("individualReport",
propMod) {
			    protected void populateItem(ListItem item) {
				Incident i = new Incident();
				i = (Incident)item.getModelObject();
				item.add(new Label("description",i.getDescription()));
                             }
                        };
         }
...
}



MARKUP FOR PANEL:

<wicket:panel>
	

	              Incidents 
		<div wicket:id="newIncButton" class="newIncButton">new+</div>
	

	<div wicket:id="repeaterContainer"id="incidentReports">
		<div wicket:id="individualReport" id="individualReport">
			<div wicket:id="description"></div>
		</div>
	</div>
</wicket:panel>


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/adding-items-dynamically-to-ListView-tp3580840p3582606.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: adding items dynamically to ListView

Posted by James Carman <jc...@carmanconsulting.com>.
How do you set up the model?  Can we see some code?

Sent from tablet device.  Please excuse typos and brevity.
On Jun 7, 2011 6:13 PM, "wmike1987@gmail.com" <wm...@gmail.com> wrote:
> Wicket doesn't allow me to update a ListView object directly through ajax,
it
> suggests putting it in in a container. So I made a WebMarkupContainer to
> wrap the ListView. I have now:
>
>
> public void onClick(AjaxRequestTarget target)
> {
> List list = new ArrayList(bean.getIncList());
> Incident inc = new Incident();
> inc.setAction("action");
> inc.setDescription("whatever description");
> list.add(inc);
> bean.setIncList(list);
> listView.modelChanged();
> container.modelChanged();
> container.setOutputMarkupId(true);
> listView.setOutputMarkupId(true);
> container.add(listView);
> target.addComponent(container);
> }
>
>
> I've confirmed that the model is being updated. The component is still not
> being redrawn.
>
> --
> View this message in context:
http://apache-wicket.1842946.n4.nabble.com/adding-items-dynamically-to-ListView-tp3580840p3580990.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: adding items dynamically to ListView

Posted by "wmike1987@gmail.com" <wm...@gmail.com>.
Wicket doesn't allow me to update a ListView object directly through ajax, it
suggests putting it in in a container. So I made a WebMarkupContainer to
wrap the ListView. I have now:


public void onClick(AjaxRequestTarget target)
	{
		List list = new ArrayList(bean.getIncList());
		Incident inc = new Incident();
		inc.setAction("action");
		inc.setDescription("whatever description");
		list.add(inc);
		bean.setIncList(list);
		listView.modelChanged();
		container.modelChanged();
		container.setOutputMarkupId(true);
		listView.setOutputMarkupId(true);
		container.add(listView);
		target.addComponent(container);
	}


I've confirmed that the model is being updated. The component is still not
being redrawn.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/adding-items-dynamically-to-ListView-tp3580840p3580990.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: adding items dynamically to ListView

Posted by Martin Grigorov <mg...@apache.org>.
On Tue, Jun 7, 2011 at 11:20 PM, wmike1987@gmail.com
<wm...@gmail.com> wrote:
> sorry, trying to format that
>
> AjaxLink newIncButton = new AjaxLink("newIncButton"){
>        @Override
>        public void onClick(AjaxRequestTarget target) {
>             List list = new ArrayList(bean.getIncList());
>               Incident inc = new Incident();
>               inc.setAction("action");
>               inc.setDescription("whatever description");
>               list.add(0, inc);
>               bean.setIncList(list);
listView.modelChanged();
target.addComponent(listView);
>             }
> }
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/adding-items-dynamically-to-ListView-tp3580840p3580846.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
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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


Re: adding items dynamically to ListView

Posted by "wmike1987@gmail.com" <wm...@gmail.com>.
sorry, trying to format that

AjaxLink newIncButton = new AjaxLink("newIncButton"){
	@Override
	public void onClick(AjaxRequestTarget target) {
             List list = new ArrayList(bean.getIncList());
	       Incident inc = new Incident();
	       inc.setAction("action");
	       inc.setDescription("whatever description");
	       list.add(0, inc);
	       bean.setIncList(list);
             }
}



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/adding-items-dynamically-to-ListView-tp3580840p3580846.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