gpt4 book ai didi

java - Vaadin:带有表单的自定义布局 [文本字段标题和必需的指示符]

转载 作者:行者123 更新时间:2023-11-29 06:12:53 26 4
gpt4 key购买 nike

我们正在开发一些 Form,但在 Vaadin Forms 中使用 CustomLayout。我们在 HTML 中使用了 Field Label 并希望取消 TextField Caption。还想在文本字段的左侧制作必需的属性。

图形设计人员和开发人员之间的任务是分离的,因此自定义布局对我们来说很方便,所以我们现在不能使用任何其他布局。

目前我的测试画面如下,【在Form中只添加了两个字段用于自定义布局】如您所见,“你好”标题位于文本框的顶部,我想将其完全删除。此标题仅用于说明目的,否则我将其设为空,但表格中仍有空间。我还想让所需的指示符与文本框对齐。

我制作了一个 Form Field 工厂并尝试了很多选项但没有成功。

如果需要任何特定的 CSS 更改,请清楚地告诉我如何添加它,因为我是 CSS 新手。根据之前对论坛的讨论,我在我的 TextField 中添加了以下样式但没有成功,

myLabel.setStyleName("inline");

并使用 CSS:

.inline, .inline div { display: inline; }

enter image description here[我的情况是将其添加到 TextField 对象中 }

最佳答案

“还想在文本字段的左侧制作必填属性”如果你想制作必填字段你应该为它设置属性.setRequired(true);

如果你想手动处理表单中的所有元素位置,你应该这样做:

public class YourFormextends Form{

private YourForm() {

setImmediate(true);
setValidationVisible(false);
setValidationVisibleOnCommit(false);
setValidationVisible(false);
setValidationVisibleOnCommit(false);
setWriteThrough(false);

VerticalLayout formLayout = createFormLayout();
setLayout(formLayout);

setFormFieldFactory(yourFormFieldFactory());
}

public static VerticalLayout createFormLayout() {
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);

final VerticalLayout formErrorLayout = new VerticalLayout();
final VerticalLayout formFieldLayout = formFieldLayout();

layout.addComponent(formErrorLayout, CREATE_FORM_ERROR_LAYOUT_INDEX);
layout.addComponent(formFieldLayout, CREATE_FORM_FIELD_LAYOUT_INDEX);

return layout;
}

private static VerticalLayout formFieldLayout() {
VerticalLayout rootLayout = new VerticalLayout();
rootLayout.setSpacing(true);
rootLayout.setMargin(false, false, true, false);
GridLayout layout = new GridLayout();

layout.setRows(1);
layout.setColumns(3);

rootLayout.addComponent(layout);

return rootLayout;

}

private FormFieldFactory activityFormFieldFactory() {
FormFieldFactory factory = new FormFieldFactory() {

private static final long serialVersionUID = 1L;

@SuppressWarnings("unchecked")
@Override
public Field createField(Item item, Object propertyId, Component uiContext) {
String fieldName = (String) propertyId;
if (fieldName.equals(FIELD_NAME_HELLO)) {

if (EDIT_MODE) {
TextField textField = new TextField(FIELD_NAME_HELLO);
textField.setRequired(true);
return textField;
}
}
}
}

@Override
protected void attachField(Object propertyId, Field field) {
String fieldName = (String) propertyId;

VerticalLayout formFieldLayout = getFormFieldLayout();

if (fieldName.equals(FIELD_NAME_HELLO)) {
GridLayout layout = (GridLayout) formFieldLayout.getComponent(0);
layout.addComponent(fieldCaption, 0, 0);
layout.addComponent(field, 1, 0);
layout.addComponent(fieldDescription, 2, 0);
}
}
}


}

关于java - Vaadin:带有表单的自定义布局 [文本字段标题和必需的指示符],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6189963/

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