gpt4 book ai didi

java - setVisibleItemProperties 无效 VAADIN

转载 作者:行者123 更新时间:2023-12-02 07:16:46 26 4
gpt4 key购买 nike

我使用 Vaadin 电话簿示例并尝试进行一些修改并制作一个新应用程序。我需要更改表单字段的名称,我按如下方式更改了它。但之后没有显示任何项目。添加后仅显示 2 个按钮

        editorForm.setVisibleItemProperties(new Object[] { "First Name",
"Last Name", "Phone Number", "Street", "City", "Postal Code",
"Brand/Item" });

line.i在setItemDataSource之前和setItemDataSource之后输入它。但结果相同。当我删除上面的行时,表单将正确弹出并显示所有内容都是正确的

package com.vaadin.demo.jpaaddressbook;

import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Vector;

import com.vaadin.addon.beanvalidation.BeanValidationForm;
import com.vaadin.data.Item;
import com.vaadin.demo.jpaaddressbook.domain.Person;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Component;
import com.vaadin.ui.DefaultFieldFactory;
import com.vaadin.ui.Field;
import com.vaadin.ui.Form;
import com.vaadin.ui.FormFieldFactory;
import com.vaadin.ui.TextField;
import com.vaadin.ui.Window;

@SuppressWarnings("serial")
public class PersonEditor extends Window implements Button.ClickListener,
FormFieldFactory {

private final Item personItem;
private Form editorForm;
private Button saveButton;
private Button cancelButton;

public PersonEditor(Item personItem) {
this.personItem = personItem;
editorForm = new BeanValidationForm<Person>(Person.class);
editorForm.setFormFieldFactory(this);
editorForm.setWriteThrough(false);
editorForm.setImmediate(true);


editorForm.setVisibleItemProperties(new Object[] { "First Name",
"Last Name", "Phone Number", "Street", "City", "Postal Code",
"Brand/Item" });


editorForm.setItemDataSource(personItem, Arrays.asList("firstName",
"lastName", "phoneNumber", "street", "city", "zipCode",
"department"));

saveButton = new Button("Save", this);
cancelButton = new Button("Cancel", this);

editorForm.getFooter().addComponent(saveButton);
editorForm.getFooter().addComponent(cancelButton);
getContent().setSizeUndefined();
addComponent(editorForm);
setCaption(buildCaption());
}

/**
* @return the caption of the editor window
*/
private String buildCaption() {
return "Enter Contact Details";
}

/*
* (non-Javadoc)
*
* @see com.vaadin.ui.Button.ClickListener#buttonClick(com.vaadin.ui.Button.
* ClickEvent)
*/
@Override
public void buttonClick(ClickEvent event) {
if (event.getButton() == saveButton) {
editorForm.commit();
fireEvent(new EditorSavedEvent(this, personItem));
} else if (event.getButton() == cancelButton) {
editorForm.discard();
}
close();
}

/*
* (non-Javadoc)
*
* @see com.vaadin.ui.FormFieldFactory#createField(com.vaadin.data.Item,
* java.lang.Object, com.vaadin.ui.Component)
*/
@Override
public Field createField(Item item, Object propertyId, Component uiContext) {
if ("department".equals(propertyId)) {
return new DepartmentSelector();
}

Field field = DefaultFieldFactory.get().createField(item, propertyId,
uiContext);
if (field instanceof TextField) {
((TextField) field).setNullRepresentation("");
}
return field;
}

public void addListener(EditorSavedListener listener) {
try {
Method method = EditorSavedListener.class.getDeclaredMethod(
"editorSaved", new Class[] { EditorSavedEvent.class });
addListener(EditorSavedEvent.class, listener, method);
} catch (final java.lang.NoSuchMethodException e) {
// This should never happen
throw new java.lang.RuntimeException(
"Internal error, editor saved method not found");
}
}

public void removeListener(EditorSavedListener listener) {
removeListener(EditorSavedEvent.class, listener);
}

public static class EditorSavedEvent extends Component.Event {

private Item savedItem;

public EditorSavedEvent(Component source, Item savedItem) {
super(source);
this.savedItem = savedItem;
}

public Item getSavedItem() {
return savedItem;
}
}

public interface EditorSavedListener extends Serializable {
public void editorSaved(EditorSavedEvent event);
}

}

最佳答案

setVisibleItemProperties 方法用于定义表单中的可见字段,而不是定义字段的标题。

以下是为表单中的字段设置标题的一个示例:

form.getField("firstName").setCaption("First Name");

另一种方法是创建您自己的 FieldFactory,为您的字段设置标题(例如基于注释)。

关于java - setVisibleItemProperties 无效 VAADIN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14837810/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com