Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Sign InSign Up

Softans

Softans Logo Softans Logo
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
Home/ Questions/Q 3042
Answered
Ghulam Nabi
Ghulam Nabi
Asked: August 14, 20222022-08-14T09:35:44+00:00 2022-08-14T09:35:44+00:00

Vaadin 23 VirtualList with 50 or more items loses ClickListener and is not refreshed

Context: In a Vaadin 23.1.3 application there’s a VirtualList with items with a ClickListener that refreshes the content of the item.

What works: When there are 3 items in the VirtualList, the ClickListener works fine and after calling callingRefreshItem the item in the VirtualList is re-rendered.

This is how the VirtualList looks like after I clicked the item with id=”id2″ 6 times (the counter counts up (equals 6) and LocalDateTime is updated, as expected):

VirtualList after some clicks

What does not work: When there are 7000 items in the VirtualList, (a) the ClickListener stops working after calling refreshItem and (b) the item that should get refreshed (by refreshItem) is not refreshed.

This is how the list looks like with e.g. 7000 items after clicking some items (counter is not refreshed and LocalDateTime is not refreshed):

VirtualList not refreshing

Code:

@Route("sandbox")
public class SandboxView extends VerticalLayout {

private static class Item {
    String id;
    int clicked=0;
    public Item(String id) {
        super();
        this.id = id;
    }
    @Override
    public boolean equals(Object obj) {
        return this.id.equals(((Item)obj).id);
    }
}

public SandboxView() {
    int numberOfItems = 7000;
    VirtualList<Item> vlist = new VirtualList<>();
    List<Item> items = new ArrayList<>();
    for (int i=0;i<numberOfItems;i++) {
        items.add(new Item("id"+i));
    }
    ListDataProvider<Item> dataProvider = new ListDataProvider<Item>(items);
    vlist.setDataProvider(dataProvider);
    vlist.setRenderer(new ComponentRenderer<Div, Item>(item -> {
            Div div = new Div();
            div.addClickListener(e -> {item.clicked++;System.out.println(item.id + " clicked "+item.clicked+"x");dataProvider.refreshItem(item, true);});
            div.add(item.id+" "+item.clicked+" " +LocalDateTime.now());
            return div;
        }
    ));
    this.add(vlist);
}
}

Further observations:

  • It seems that this behavior starts with 50 items in the VirtualList.
  • When I scroll away from a broken item and then scroll to the broken item back, the values at the item are refreshed, the ClickListener is present and I can use it a single time. Then I have to scroll away and back again.
  • (Update) There is a JavaScript error in the browser: The error has occurred in the JS code: '$0, $1, return $0.$connector.updateData($1)' and this message: JavaScript error message

Question: How can I refresh an item in a large VirtualList without losing ClickListeners?

clicklistenervaadin
  • 0
  • 1 1 Answer
  • 18 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

1 Answer

  • Voted
  • Oldest
  • Recent
  1. Best Answer
    Ghulam Nabi
    2022-08-14T09:36:30+00:00Added an answer on August 14, 2022 at 9:36 am

    In Vaadin 23.1.6 this is fixed.

    https://github.com/vaadin/flow-components/issues/3487#issuecomment-1191292376

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • Popular
  • Answers
  • Ghulam Nabi

    Why are the British confused about us calling bread rolls ...

    • 5 Answers
  • Alex

    application has failed to start because no appropriate graphics hardware ...

    • 4 Answers
  • Jerry

    Add file to native target programmatically via tuist/XcodeProj

    • 4 Answers
  • Ghulam Nabi
    Ghulam Nabi added an answer To resolve the NullPointerException, you need to identify the variable… March 15, 2023 at 8:25 am
  • Ghulam Nabi
    Ghulam Nabi added an answer You can replace the PnP code in your Azure Function… February 13, 2023 at 7:11 am
  • Ghulam Nabi
    Ghulam Nabi added an answer You can use the $match stage in the aggregate pipeline… February 10, 2023 at 6:20 am

Trending Tags

android c++ cypress flutter java javascript python selenium testng webdriver

Top Members

Robert

Robert

  • 3 Questions
  • 1k Points
Luci

Luci

  • 5 Questions
  • 1k Points
Kevin O Brien

Kevin O Brien

  • 2 Questions
  • 1k Points

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Softans

Softans is a social questions & Answers Engine which will help you establish your community and connect with other people.

About Us

  • Blog
  • Jobs
  • About Us
  • Meet The Team
  • Contact Us

Legal Stuff

Help

Follow

© 2021 Softans. All Rights Reserved
With Love by Softans.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.