Field Factory erros

Hi, I’m new at this forum, I tried to search about my problem but was in vain so far.

I’m student and I’m trying to develop a web-app to train my skills, I grab the “FormAdvancedLayoutExample” from the vaadin sampler and I’m trying to put in my code,
but i’m having some troubles to set this right.

This is my Field Factory Class, first when I tried to open the window I got this error message: “Caused by: java.lang.ClassCastException: com.vaadin.ui.DateField cannot be cast to com.vaadin.ui.PopupDateField”.

Ok. I commented the lines with the PopupDateField and the window shows up, but something very odd is happening, the data fields are showing up in the window, I don’t know from where it comes.

public class PlanoIntegradoFieldFactory extends DefaultFieldFactory{

	final ComboBox countries = new ComboBox("Country");
	private static final String COMMON_FIELD_WIDTH = "12em";

    public PlanoIntegradoFieldFactory() {
        countries.setWidth("100%");
        countries.setContainerDataSource(ExampleUtil.getISO3166Container());
        countries.setItemCaptionPropertyId(ExampleUtil.iso3166_PROPERTY_NAME);
        countries.setItemIconPropertyId(ExampleUtil.iso3166_PROPERTY_FLAG);
        countries.setFilteringMode(ComboBox.FILTERINGMODE_STARTSWITH);
    }

    @Override
    public Field createField(Item item, Object propertyId, Component uiContext) {
        Field f;
        if ("idPlano".equals(propertyId)) {
            
            return countries;
        } else {
            // Use the super class to create a suitable field base on the
            // property type.
            f = super.createField(item, propertyId, uiContext);
        }
        if ("nmPlano".equals(propertyId)) {
            TextField tf = (TextField) f;
            String nullRepresentation = "";
            tf.setRequired(true);
            tf.setRequiredError("Nome do plano integrado");
            tf.setWidth(COMMON_FIELD_WIDTH);     
			tf.setNullRepresentation(nullRepresentation );
            tf.addValidator(new StringLengthValidator(
                    "Nome do plano precisa ter no mínimo 3-25 caracteres", 3, 25, false));
    	} else if ("dtIniPlano".equals(propertyId)) {
            //PopupDateField dt = (PopupDateField) f;
            //dt.setRequired(true);
            //dt.setRequiredError("Data inicial do plano integrado");
            //dt.setWidth(COMMON_FIELD_WIDTH);
       
        } else if ("dtFimPlano".equals(propertyId)) {
            //PopupDateField dt = (PopupDateField) f;
            //dt.setRequired(true);
            //dt.setRequiredError("Data final do plano integrado");
            //dt.setWidth(COMMON_FIELD_WIDTH);
        } 
        return f;
    }
}

This is the image from my web app,

http://imageshack.us/f/268/semttulosdq.png/

And another question, how can I cut off this countries combo box from the code?
I tied to take off but this return statement I don’t know what to do with that, I just want my fields.

final ComboBox countries = new ComboBox("Country");
	private static final String COMMON_FIELD_WIDTH = "12em";

    public PlanoIntegradoFieldFactory() {
        countries.setWidth("100%");
        countries.setContainerDataSource(ExampleUtil.getISO3166Container());
        countries.setItemCaptionPropertyId(ExampleUtil.iso3166_PROPERTY_NAME);
        countries.setItemIconPropertyId(ExampleUtil.iso3166_PROPERTY_FLAG);
        countries.setFilteringMode(ComboBox.FILTERINGMODE_STARTSWITH);
    }

    @Override
    public Field createField(Item item, Object propertyId, Component uiContext) {
        Field f;
        if ("idPlano".equals(propertyId)) {
            
            return countries;
        } else {
            // Use the super class to create a suitable field base on the
            // property type.
            f = super.createField(item, propertyId, uiContext);
        }

Sorry about my English and thanks All.

//this will generate a field using DefaultFieldFactory
//so it creates com.vaadin.ui.DateField for Date types
// casting that to PopupDateField doesn't work.
f = super.createField(item, propertyId, uiContext);

You could do e.g.

if (item.getItemProperty(propertyId).getType().equals(Date.class)) { f = new PopupDateField(); }

You can set the visible item properties for a Form.setVisibleItemProperties(). For that you give a collection of property ids.
Leave “idPlano” out of it, you don’t want that field generated from your data.

Thanks for the help, it works! :grin:

I just didn’t understand how to take this combo box component off the code:

final ComboBox countries = new ComboBox("Country");//this came with the vaadin sampler and I don't want it.
	private static final String COMMON_FIELD_WIDTH = "12em";

	public PlanoIntegradoFieldFactory() {//this came with the vaadin sampler and I don't want it.
		countries.setWidth("100%");//this came with the vaadin sampler and I don't want it.
		countries.setContainerDataSource(ExampleUtil.getISO3166Container());//this came with the vaadin sampler and I don't want it.
		countries.setItemCaptionPropertyId(ExampleUtil.iso3166_PROPERTY_NAME);//this came with the vaadin sampler and I don't want it.
		countries.setItemIconPropertyId(ExampleUtil.iso3166_PROPERTY_FLAG);//this came with the vaadin sampler and I don't want it.
		countries.setFilteringMode(ComboBox.FILTERINGMODE_STARTSWITH);//this came with the vaadin sampler and I don't want it.
	}

	@Override
	public Field createField(Item item, Object propertyId, Component uiContext) {

		Field f;
		if ("idPlano".equals(propertyId)) {

			return countries;//what I should do in here?
		} else {
			// Use the super class to create a suitable field base on the
			// property type.
			f = super.createField(item, propertyId, uiContext);
		}

Thanks all again.