In my project I have a jpa database connection where I store exercises. I read all exercises from the database and store them into the variable allExercises. Afterwards I save the title of each exercise in a button, add them to a box for the GUI and also add a click listener event that handles the navigation to the next view. This next view is a detail view of the chosen exercise. To know on which exercise I have clicked I want to pass the id of the exercise object as a parameter. For now I have following code:
for(Exercise exercise : allExercises) { // create new button with exercise title Button bt = new Button(exercise.getTitle()); // add button to box boxExerciseTitle.add(bt); // add action event bt.addClickListener(e -> UI.getCurrent().navigate(ExerciseDetailView.class, exercise.getId())); } This code is not working. There is a problem with the ID respectively that the navigate function does not handle this two arguments.
My goal is to read the parameter in the detail view like that:
public class ExerciseDetailView extends VerticalLayout implements View{ @Override public void enter(ViewChangeEvent event) { String myPassedId = event.getParameters(); ... } } How can I change my code that I can pass the id as a parameter in Vaadin?