Hey, ich habe eine kleine Website geschrieben, mir ist jedoch anscheinend ein Fehler unterlaufen, den ich nicht auffinden kann. Könnte einer von euch rüber sehen? Die Fehlermeldung lautet:
type Status report
message /YoutubeProjekt/
description The requested resource is not available.
MyUI.java
Customer:
CustomerService:
Danke jetzt schon einmal.
type Status report
message /YoutubeProjekt/
description The requested resource is not available.
MyUI.java
Java:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.vandelisim.youtubeprojekt;
import com.vaadin.annotations.Theme;
import com.vaadin.data.fieldgroup.BeanFieldGroup;
import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.server.VaadinRequest;
import com.vaadin.spring.annotation.SpringUI;
import com.vaadin.ui.Button;
import com.vaadin.ui.Grid;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
/**
*
* @author Leon
*/
@SpringUI
@Theme("valo")
public class MyUI extends UI {
@Autowired
private CustomerService service;
private Customer customer;
private Grid grid = new Grid();
private TextField firstName = new TextField("First name");
private TextField lastName = new TextField("Last name");
private Button save = new Button("Save", e -> saveCustomer());
@Override
protected void init(VaadinRequest request) {
updateGrid();
grid.setColumns("firstName", "lastName");
grid.addSelectionListener(e -> updateForm());
VerticalLayout layout = new VerticalLayout(grid, firstName, lastName,
save);
layout.setMargin(true);
layout.setSpacing(true);
setContent(layout);
}
private void updateGrid() {
List customers = service.findAll();
grid.setContainerDataSource(new BeanItemContainer<>(Customer.class,
customers));
setFormVisible(false);
}
private void updateForm() {
if (grid.getSelectedRows().isEmpty()) {
setFormVisible(false);
} else {
customer = (Customer) grid.getSelectedRow();
BeanFieldGroup.bindFieldsUnbuffered(customer, this);
setFormVisible(true);
}
}
private void setFormVisible(boolean visible) {
firstName.setVisible(visible);
lastName.setVisible(visible);
save.setVisible(visible);
}
private void saveCustomer() {
service.update(customer);
updateGrid();
}
}
Code:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.vandelisim.youtubeprojekt;
/**
*
* @author Leon
*/
public class Customer {
private Long id;
private String firstName, lastName;
public Customer(Long id, String firstName, String lastName) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public Long getId() {
return id;
}
public String getLastName() {
return lastName;
}
}
Code:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.vandelisim.youtubeprojekt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class CustomerService {
@Autowired
private JdbcTemplate jdbcTemplate;
public List findAll() {
return jdbcTemplate.query(
"SELECT id, first_name, last_name FROM customers",
(rs, rowNum) -> new Customer(rs.getLong("id"),
rs.getString("first_name"), rs.getString("last_name")));
}
public void update(Customer customer) {
jdbcTemplate.update(
"UPDATE customers SET first_name=?, last_name=? WHERE id=?",
customer.getFirstName(), customer.getLastName(), customer.getId());
}
}
Danke jetzt schon einmal.