Problem with Form and GridLayout

I would like to change the layout from

Input1

Input2

to

Input1 …
Input2 …

I tried to extend the advanced layout example but was not able to accomplish the required layout. The field is added to the right location put no label is shown.

Any ideas how to implement the required layout ?

Regards
Roger


public class DetailForm extends Form {

@Inject
	public DetailForm(EntityManager em) {
		this.em = em;
		ourLayout = new GridLayout(4, 15);
		setLayout(ourLayout);
		setFormFieldFactory(new WFieldFactory());
		setVisibleItemProperties(Arrays.asList(new String[] { "id", "endkunde" }));
		setItemDataSource(new BeanItem(new Vertrag())); 
	}

	   
       @Override
       protected void attachField(Object propertyId, Field field) {
           if (propertyId.equals("id")) {
               ourLayout.addComponent(getLabel("ID"), 0, 0);
               ourLayout.addComponent(field, 1, 0);
           } else if (propertyId.equals("endkunde")) {
               ourLayout.addComponent(getLabel("Client"), 0, 1);
               ourLayout.addComponent(field, 1, 1);
           }
       
       }
	   
      private Label getLabel(String caption) {
    	Label l = new Label();
    	l.setCaption(caption);
    	return l;
      }

      private class WFieldFactory extends DefaultFieldFactory {
		@Override
		public Field createField(Item item, Object propertyId,
				Component uiContext) {
			Field f = super.createField(item, propertyId, uiContext);
			f.setCaption("");
			return f;
		}
	}


Hi!

I’m not entirely sure that this is the problem, but you probably want to set the value of the label and not it’s caption. Labels can have both captions and values, which are different things. I.e. you can have a label with a caption.

So test changing the getLabel() method to something like this:

getLabel(String caption) {
   return new Label(caption);
}

HTH,
/Jonatan