question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get actual entity inside click listener callback.

See original GitHub issue

Hi. Spent a lot of time to find a way to get clicked entity inside clickListener callback. Have the following code

@Override
    protected void buildModels(final List<Item> items) {

        for (Item item : items) {
            new ListItemViewModel()
                    .id(item.getId())
                    .name(item.getName())
                    .clickListener()
                    .addTo(this);
        }
    }

   public interface OnItemClickListener {
        void onItemClick(Item clickedItem);
    }

I’ve tried to use just item from cycle, but as I noticed this entity cached somewhere and if it changes it’s state I still receive “old” entity with not actual fields. Is there any way to receive clicked item? Thanks.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Aug 21, 2018

Yeah, I’ve also tried this approach. It works, but seems a little bit strange to pass Reminder and then all it’s properties separately. Anyway thanks for your response.

1reaction
elihartcommented, Aug 21, 2018

I would change your ReminderListItemView to include this line

@ModelProp Reminder reminder;

then set it on the model

new ReminderListItemViewModel()
                    .id(reminder.getId())
                     .reminder(reminder)

Then in the click listener you can easily get it

.clickListener((model, parentView, clickedView, position) -> {
                                final Reminder clickedItem =  model.getReminder();
                                onReminderClickListener.onReminderClick(clickedItem);
                        }
                    })

that way you don’t have to deal with item lookup. Also, the way you are currently looking up data has potential race conditions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chapter 6. Entity listeners and Callback methods
A callback method is a no-arg method with no return type and any arbitrary name. An entity listener has the signature void <METHOD>(Object)...
Read more >
Access current user in entity lifecycle callback - Stack Overflow
the good way to do this is to use the doctrine event listener: file service.yml services: my_report_listener : class ...
Read more >
Chapter 5. Entity listeners and Callback methods
A callback method is a no-arg method with no return type and any arbitrary name. An entity listener has the signature void <METHOD>(Object)...
Read more >
Entity listeners and callback methods - IBM
Two callback mechanisms exist for state change events: lifecycle callback methods that are defined on an entity class and are invoked whenever ...
Read more >
JPA event-driven development with entity listeners
To show explained concepts in the code, let's write some test cases. But before, we need to define listeners and callback methods inside...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found