1 package com.vaadin.tests.components.abstractfield;
3 import java.util.HashSet;
6 import com.vaadin.server.VaadinRequest;
7 import com.vaadin.tests.components.AbstractTestUI;
8 import com.vaadin.ui.AbsoluteLayout;
9 import com.vaadin.ui.CheckBox;
10 import com.vaadin.ui.Component;
11 import com.vaadin.ui.ComponentContainer;
12 import com.vaadin.ui.CssLayout;
13 import com.vaadin.ui.GridLayout;
14 import com.vaadin.ui.HorizontalLayout;
15 import com.vaadin.ui.Label;
16 import com.vaadin.ui.VerticalLayout;
17 import com.vaadin.v7.ui.Field;
18 import com.vaadin.v7.ui.TextField;
20 public class RequiredIndicatorForFieldsWithoutCaption extends AbstractTestUI {
21 private Set<Field> fields = new HashSet<Field>();
24 protected void setup(VaadinRequest request) {
26 CheckBox required = new CheckBox("Fields required", true);
27 required.setImmediate(true);
28 required.addValueChangeListener(event -> {
29 boolean newRequired = event.getValue();
30 for (Field f : fields) {
31 f.setRequired(newRequired);
34 addComponent(required);
35 addComponent(createWrappedTextField(new GridLayout(2, 1)));
36 addComponent(createWrappedTextField(new VerticalLayout()));
37 addComponent(createWrappedTextField(new HorizontalLayout()));
38 AbsoluteLayout al = new AbsoluteLayout();
40 al.setHeight("100px");
41 addComponent(createWrappedTextField(al));
42 addComponent(createWrappedTextField(new CssLayout()));
50 private Component createWrappedTextField(ComponentContainer container) {
51 TextField tf = new TextField();
53 tf.setWidth(200, Unit.PIXELS);
55 container.addComponent(new Label(container.getClass().getSimpleName()));
56 container.addComponent(tf);
57 if (container instanceof AbsoluteLayout) {
58 ((AbsoluteLayout) container).getPosition(tf).setLeft(100.0f,
60 ((AbsoluteLayout) container).getPosition(tf).setTop(50.0f,
70 * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription()
73 protected String getTestDescription() {
74 return "Test for ensuring that the required indicator is visible for fields even when they would not otherwise have a caption";
80 * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber()
83 protected Integer getTicketNumber() {