Vaadin现场小组无法正常工作

时间:2016-03-31 10:26:12

标签: java vaadin7

我正在尝试实施 vaadin fieldgroup ,但它没有绑定值。

它给了我以下错误:

Communication problem Invalid JSON response from server:

这是我的代码。

模特课程:

public class LoggedCustomer {

private String Id;
private String Name;
private String Cell;
private String email;
private String address;

public String getId() {
    return Id;
}
public void setId(String id) {
    Id = id;
}
public String getName() {
    return Name;
}
public void setName(String name) {
    Name = name;
}
public String getCell() {
    return Cell;
}
public void setCell(String cell) {
    Cell = cell;
}
public String getEmail() {
    return email;
}
public void setEmail(String email) {
    this.email = email;
}
public String getAddress() {
    return address;
}
public void setAddress(String address) {
    this.address = address;
}
}

客户布局类:

public class CustomerFormView extends FormLayout {

@PropertyId("id")
private TextField id = new TextField("Customer Id");

@PropertyId("name")
private TextField name = new TextField("Customer Name");

@PropertyId("cell")
private TextField cell = new TextField("Customer Cell Number");

@PropertyId("email")
private TextField email = new TextField("Customer Email");

@PropertyId("address")
private TextField address = new TextField("Customer Address");


public CustomerFormView() {

    setSpacing(true);
    addComponent(id);
    addComponent(name);
    addComponent(cell);
    addComponent(email);
    addComponent(address);
}
}

主要用户分类:

public class LoggedIn extends UI {

@WebServlet(value = "/loggedin", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = LoggedIn.class)
public static class Servlet extends VaadinServlet {
}

@Override
protected void init(VaadinRequest request) {    
    HorizontalLayout hori = new HorizontalLayout();
    setContent(hori);
    hori.setSpacing(true);
    hori.setMargin(true);

    Item customer = createCustomer();

    hori.addComponent(createView(customer));

    hori.addComponent(displayCustomer(customer));
}

private Layout createView(Item item) {
    VerticalLayout formLayout = new VerticalLayout();
    formLayout.setMargin(true);
    formLayout.setSizeFull();

    CustomerFormView productEditLayout = new CustomerFormView();
    formLayout.addComponent(productEditLayout);

    final FieldGroup binder = new FieldGroup(item);
    binder.bindMemberFields(productEditLayout);

    HorizontalLayout footer = new HorizontalLayout();
    footer.setSpacing(true);

    footer.addComponent(new Button("Save", new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            try {
                binder.commit();
            } catch (InvalidValueException e) {

            } catch (CommitException e) {

            }
        }
    }));

    footer.addComponent(new Button("Cancel", new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            binder.discard();
        }
    }));
    formLayout.addComponent(footer);

    return formLayout;
}

private Layout displayCustomer(Item item) {
    FormLayout layout = new FormLayout();

    Label name = new Label();
    name.setPropertyDataSource(item.getItemProperty("name"));
    name.setCaption("Name");
    layout.addComponent(name);

    return layout;
}

private static Item createCustomer() {
    LoggedCustomer customer = new LoggedCustomer();
    customer.setName("");
    customer.setId("");
    customer.setCell("");
    customer.setEmail("");
    customer.setAddress("");
    return new BeanItem<LoggedCustomer>(customer);
}
}

这是我正在使用的应用程序的完整代码,但是fieldgroup binder无法正常工作并且出错。

请有人帮我确定问题出在哪里以及我在代码中做错了什么。

我将感恩....:)

0 个答案:

没有答案