Reputation: 558
I want to create simply page where the vaadin's grid will be displayed with data from database. Unfortunately I didnt find any solution in documentation or movies... So, I have my JPA class:
@Entity
@Table
public class Movie {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column
private String movieName;
@Column
private String description;
public Movie(){}
public Movie(String movieName, String description) {
this.movieName = movieName;
this.description = description;
}
With all getters and setters. And now I want to create GUI:
@Route("show-movies")
public class MovieGUI extends VerticalLayout{}
And I tried everything: Grid < Movie>,initializeGrid, but nothing works. I just want to in simple way add 3 columns(name,desc and action) and display data from my db and button to create action. Does anyone know how to solve this problem?
Upvotes: 0
Views: 267
Reputation: 1923
Something along these lines:
@Route("show-movies")
public class MovieGUI extends VerticalLayout{
MovieGUI(MovieRepository repo) {
Grid<Movie> movieGrid = new Grid<>();
movieGrid.setItems(repo.findAll());
movieGrid.addColumn(Movie::getName).setHeader("Name");
movieGrid.addColumn(Movie::getDescription).setHeader("Description");
movieGrid.addComponentColumn(movie -> new NativeButton("Action", click-> doSomething(movie)).setHeader("");
add(movieGrid);
}
}
Check out the demo sources here for more examples: https://vaadin.com/components/vaadin-grid/java-examples
Upvotes: 1