I am totaly new in Vaadin, I like it but alas I have little knowledge of it. Forgive me if my question will be simple for most of you here
And I am sorry for long thread.
I have followed tutorial http://www.alejandrodu.com/blog/lazy-loading-with-vaadin-8 great stuff, it works but I wanted to implement this fill of grid in View, and I also folowed video https://www.youtube.com/watch?v=S1_vvip5uzc which I found very nice to show me how to make nice login and then a dashboard page
To explain what I did
I have myUI (this is from video)
@SpringUI
public class myUI extends UI {
@Override
protected void init(VaadinRequest vaadinRequest) {
Navigator navigator = new Navigator(this, this);
navigator.addView("login", new Login());
navigator.addView("dashboard", new Dashboard());
navigator.navigateTo("login");
}
}
Dashboard (this is from video)
public class Dashboard extends VerticalLayout implements View {
HorizontalLayout upperSection = new HorizontalLayout();
HorizontalLayout innerUpperSection = new HorizontalLayout();
HorizontalSplitPanel lowerSection = new HorizontalSplitPanel();
VerticalLayout menuLayout = new VerticalLayout();
HorizontalLayout menuTitle = new HorizontalLayout();
VerticalLayout contentLayout = new VerticalLayout();
Label lblHeader;
Label lblMenu;
Button btnLogout;
public Dashboard(){
//UI Components
....manu things here that work as in video
public Component getComponent(String componentName) {
if (componentName.equals("Devices")) {
return new Devices();
} else if (componentName.equals("History")) {
return new History();
} else if (componentName.equals("Stocks")) {
return new Stocks();
}else if (componentName.equals("Orders")) {
return new Orders();
}else { //reports
return new Reports();
}
}
public void addMenuOption(String caption, String componentName) {
Button button = new Button(caption);
button.setWidth("100%");
button.setStyleName("borderless");
menuLayout.addComponent(button);
button.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
contentLayout.removeAllComponents();
contentLayout.addComponent(getComponent(componentName));
}
});
}
....many things here again that work as in video
}
webService class (this is from tutorial)
@Service
public class web_Service {
private final web_Repository repository;
public web_Service(web_Repository repository) {
this.repository = repository;
}
public List<web> findAll(int offset, int limit, Map<String, Boolean> sortOrders) {
int page = offset / limit;
List<Sort.Order> orders = sortOrders.entrySet().stream()
.map(e -> new Sort.Order(e.getValue() ? Sort.Direction.ASC : Sort.Direction.DESC, e.getKey()))
.collect(Collectors.toList());
PageRequest pageRequest = new PageRequest(page, limit, orders.isEmpty() ? null : new Sort(orders));
List<web> items = repository.findAll(pageRequest).getContent();
return items.subList(offset%limit, items.size());
}
public Integer count() {
return Math.toIntExact(repository.count());
}
}
repository (this is from tutorial)
@Repository
public interface Web_Repository extends JpaRepository<web, Long> {
}
web class
@Entity
public class web {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String SN;
private String Location;
private String Model;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getSN() {
return SN;
}
public void setSN(String SN) {
this.SN = SN;
}
public String getLocation() {
return Location;
}
public void setLocation(String location) {
this.Location = location;
}
public String getModel() {
return Model;
}
public void setModel(String model) {
this.Model = model;
}
}
what I have is class called Devices
public class Devices extends VerticalLayout implements View {
//this I addes as in tutorial
private print_nis_devices_Service service;
private Grid<print_nis_devices> grid;
//this also like in tutorial but I think this the issue, and thats why I need help
public Devices(print_nis_devices_Service service) {
this.service = service;
}
public Devices() {
setSizeFull();
grid = new Grid<>(print_nis_devices.class);
grid.setSizeFull();
grid.setDataProvider(
(sortOrders, offset, limit) -> {
Map<String, Boolean> sortOrder = sortOrders.stream()
.collect(Collectors.toMap(
sort -> sort.getSorted(),
sort -> sort.getDirection() == SortDirection.ASCENDING));
return service.findAll(offset, limit, sortOrder).stream();
},
() -> service.count()
);
addComponent(grid);
setExpandRatio(grid, 1);
}
}
I am getting when I click in Dashboard on Devices empty grid, columns are created but empty, if I do this in myUI then it works, I know something needs to be done in Devices.class but I am clueless what?
Any help appreciated
Thank you