Dynamic Form

Hi,

I’v read the book on the part speaking about the Form and I want to know if it’s possible to use vaadin Form with a kind of dynamic JavaBean.

Assume I want to use this item :

/** A simple JavaBean. */
public class PersonBean {
    String name;
    String city;
    
    public void setName(String name) {
        this.name = name;
    }
    public String getName() {
        return name;
    }
    public void setCity(String city) {
        this.city = city;
    }
    public String getCity() {
        return city;
    }
}

This is a fixed JavaBean !

Now I want to use a kind of javabean defined like that :

public class PersonBean {
    List<Field>
}

where Field is defined like that


public class Field{
     String Type
     String Data
     
      //getters and setters ...
}

Is there a function In beanItem where we can add “manualy” getter and setter for each field inside a JavaBean ?
Or mayabe a workaround for this limitation …

Greatings

Ok I may use form.addField(“name of field”,new TextField()) or Label or… etc.)

which both argument can ben include in a loop while/for depending on data I can get from database

PropertyserItem might be what you are looking for:
http://vaadin.com/api/com/vaadin/data/util/PropertysetItem.html

Also note that it is really easy to implement Item interface yourself. Just implement http://vaadin.com/api/com/vaadin/data/Item.html

Any Item implementation can be connected to a Form.

Thx for this quick response.

I imagine, I Have to do the following trick :

public class ChampsItem extends Champs implements Item{
	
	

	@Override
	public boolean addItemProperty(Object id, Property property)
			throws UnsupportedOperationException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Property getItemProperty(Object id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Collection<?> getItemPropertyIds() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean removeItemProperty(Object id)
			throws UnsupportedOperationException {
		// TODO Auto-generated method stub
		return false;
	}
}

where “Champs” is my own JavaBean

I will try to manage myself to use this Item, but I think the logical databinding of vaadin is more difficult to understand than using it in a standard way (as described in the book)

by the way, all the remaining explainations in the book are well performed !

I’m still stucked on the implementation of this Item (especially cauz I’m a noob @ java :p)

Can you post me some exemple into implementing a beanitem on our own ?
Static Form are definitly easy to use but dynamic ones … :*)

Thx