• Home
  • RSS Feed
  • Log in

Mischa Dasberg

Wicket – Updating ListViews using an AjaxLink
Posted by Mischa Dasberg mid-morning: June 4th, 2008

Consider the following senario: we want to display some data in a table like manner, and we want it to update when we click on a link or button. We do not want to do a complete page refresh, we want it in an ajax way. Also we would like the modify the css for each cell.

In wicket you can use a ListView iterate over a List of Objects and display them in a table like manner.
This blog describes how you can update ListView data and modify the css for each cell.

So how do we start?

Well first we need to create a ListView. Lets call it view.
But before we do that we need a List of objects we want to display. So lets create it.
I use a List of TestObject’s.

As you can see below, this isn’t very hard.

private ListView view;
private List objects;

objects = Arrays.asList(new TestObject[] {
    new TestObject("one", true),
    new TestObject("two", false),
    new TestObject("three", true)});

view = new ListView("view", objects) {
    @Override
    protected void populateItem(ListItem item) {
        Label label = new Label("label", new PropertyModel(item.getModel(), "name"));
        label.setOutputMarkupId(true);
        item.add(label);
    }
};

Next we will create an IndicatingAjaxFallbackLink which is basically a AjaxLink that shows an indicator.

private IndicatingAjaxFallbackLink link;

link = new IndicatingAjaxFallbackLink("link") {
    @Override
    public void onClick(AjaxRequestTarget target) {
        objects = Arrays.asList(new TestObject[] {
            new TestObject("four", false),
            new TestObject("five", true),
            new TestObject("six", false)});
        view.setList(objects);
        target.addChildren(view, Label.class);
    }
};

Thats all. Now see that we add a new List of objects to the ListView. To make sure the ListView is updated we add

target.addChildren(view, Label.class);

instead of

target.addComponent(view);

. As a ListView is a repeater, we cannot updated it, but we can update components in a ListView.

So now we can update a ListView, but how do we change the css for each field?

We add an AttributeModifier. In the populateItem method show above we just add the following

label.add(new AttributeModifier("class", true, new PropertyModel(item.getModel(), "odd") {
    @Override
    public Object getObject() {
        return ((Boolean) super.getObject()) ? "odd" : "even";
    }
}));

The getObject method is overridden, because the method getOdd() on the TestObject returns a boolean. So instead of returning true or false, it now returns “odd” or “even” which are css class styles.

That’s it.

I have attached the example project here so you can look into the code yourself.

Share

Tags: Ajax, Java, Wicket
Filed under Java | 15 Comments »



15 Responses to “Wicket – Updating ListViews using an AjaxLink”



    50 Excellent AJAX Tutorials | Tutorials | Smashing Magazine Says:
    Posted at: October 16, 2008 at 11:47 pm

    [...] Wicket – Updating ListViews Using an AjaxLink Create a table that will update without a full page refresh when a link is clicked. [...]

    Reply


    Useful AJAX Tutorials | Neurosoftware web dev Says:
    Posted at: October 17, 2008 at 8:59 am

    [...] Wicket – Updating ListViews Using an AjaxLink Create a table that will update without a full page refresh when a link is clicked. [...]

    Reply


    50+ Great Ajax Tutorial | Tech User, Blogger and Designers References Says:
    Posted at: October 21, 2008 at 1:35 pm

    [...] Wicket – Updating ListViews Using an AjaxLink Create a table that will update without a full page refresh when a link is clicked. [...]

    Reply


    50 Excellent AJAX Tutorials | Evolution : weblog Says:
    Posted at: October 31, 2008 at 6:27 am

    [...] Wicket – Updating ListViews Using an AjaxLink Create a table that will update without a full page refresh when a link is clicked. [...]

    Reply


    50 Excellent AJAX Tutorials | How2Pc Says:
    Posted at: December 19, 2008 at 9:37 am

    [...] Wicket – Updating ListViews Using an AjaxLinkCreate a table that will update without a full page refresh when a link is clicked. [...]

    Reply


    50 Excellent AJAX Tutorials « Rohit Dubal Says:
    Posted at: February 16, 2009 at 11:38 am

    [...] Wicket – Updating ListViews Using an AjaxLink Create a table that will update without a full page refresh when a link is clicked. [...]

    Reply


    Best Ajax Tutorials and Dynamic Solution for PHP ,Asp.net.Ruby On Rrails | Click On Tech Says:
    Posted at: February 23, 2009 at 3:18 pm

    [...] Wicket – Updating ListViews Using an AjaxLink Create a table that will update without a full page refresh when a link is clicked. [...]

    Reply


    150 AJAX Tutorials » TemplateLite.com Says:
    Posted at: May 14, 2009 at 2:10 am

    [...] Wicket – Updating ListViews Using an AjaxLink – This tutorial shows how to create a table that will update without a full-page refresh when a link is clicked. [...]

    Reply


    Best of 158 Ajax Framework,JavaScript Libraries and Toolkit Tutorials | Click On Tech Says:
    Posted at: May 14, 2009 at 12:23 pm

    [...] Wicket – Updating ListViews Using an AjaxLink – This tutorial shows how to create a table that will update without a full-page refresh when a link is clicked. [...]

    Reply


    Ajax Frameworks,JavaScript Libraries and Toolkit Tutorials | Dev Techie Says:
    Posted at: May 15, 2009 at 4:46 am

    [...] Wicket – Updating ListViews Using an AjaxLink - This tutorial shows how to create a table that will update without a full-page refresh when a link is clicked. [...]

    Reply


    Geek is a Lift-Style. » 50 Excellent AJAX Tutorials Says:
    Posted at: June 18, 2010 at 10:10 am

    [...] Wicket – Updating ListViews Using an AjaxLink Create a table that will update without a full page refresh when a link is clicked. [...]

    Reply


    Daniel Geffert Says:
    Posted at: April 1, 2011 at 7:58 pm

    Spot on with this write-up, I truly think this website wants way more consideration. I’ll most likely be again to learn rather more, thanks for that info.

    Reply


    Bindu Says:
    Posted at: September 13, 2011 at 8:23 pm

    Thanks for the code! I was looking for something similar like this.

    Reply


    Ferry Says:
    Posted at: September 29, 2011 at 11:04 am

    Cool, Thanks for sharing this with us :-)

    Reply


    sc_bant Says:
    Posted at: October 27, 2011 at 10:35 am

    thx,guy.

    I forget the ~view.setList(objects);~ mathod.

    the damn mind TAT

    Reply


Leave a Reply

Click here to cancel reply.


Xebia Sites

  • Xebia Corporate
  • Xebia France
  • Xebia India
  • Xebia Sweden

Categories

  • Java (311)
  • Agile (181)
  • General (136)
  • Scrum (67)
  • Architecture (64)
  • Testing (59)
  • Performance (46)
  • Middleware (56)
    • Deployment (38)
  • Xebia Labs (39)
  • SOA (31)
  • Podcast (31)
  • Project Management (28)
  • Tools (26)
  • Uncategorized (20)
  • lean architecture (20)
  • Quality Assurance (17)
  • Articles (13)
  • Requirements Management (13)
  • Virtualization (19)

Tag Cloud

    Lean Maven TDD Frameworks Xebia Ajax XML Hibernate ACT lean architecture JPA Grails JPA implementation patterns Flex Oracle Eclipse Architecture Spring Moving to India Groovy product owner agile architectuur Concurrency Control Javascript lean architectuur Scala SOA Java Scrum Agile

Archives

  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
Avatars by Sterling Adventures