filter field

I have one filter table ,in that table one column is there which is storing bolean value from database,on top of the table in filterField is displaying which is containing true and false I need it “Yes” ,“No” How to change it .

please someone help me.

Thanks

You need to apply a Converter for the property. You can apply a converter for a specific property of a table by calling table.setConverter(propertyId, converter). Here is an example application that does what you want.

@Override
protected void init(VaadinRequest request) {
Table table = new Table();
table.setSizeFull();
setContent(table);

IndexedContainer container = new IndexedContainer();
container.addContainerProperty("foobar", Boolean.class, false);
container.addItem(1).getItemProperty("foobar").setValue(false);
table.setContainerDataSource(container);

table.setConverter("foobar", new Converter<String, Boolean>() {

@Override
public Boolean convertToModel(String value,
Class<? extends Boolean> targetType, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
return "Yes".equals(value);
}

@Override
public String convertToPresentation(Boolean value,
Class<? extends String> targetType, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
return value? "Yes" : "No";
}

@Override
public Class<Boolean> getModelType() {
return Boolean.class;
}

@Override
public Class<String> getPresentationType() {
return String.class;
}

}) ;

}

Hi, Kim Leppanen,Thanks very much it is working fine

I have one Bean which contains Like this:
class MyBean{
private Number columnWidth;

public Number getColumnWidth() {
    return columnWidth;
}

public void setColumnWidth(Number columnWidth) {
    this.columnWidth = columnWidth;
}    

}

the setter method is getting populated from another class like:
myBean.setColumnWidth((Number) item.getBean()
.getColumnWidth());

MyView is a class like :

class MyView{

import …FilterTable

FilterTable table;
table.setColumnWidth(“propId”,myBean.getColumnWidth())//here getting error the error mentioned below
}
Error getting:
The method setColumnWidth(Object, int) in the type CustomTable is not applicable for the arguments (String, Number)

I tried to cast it with Integer but getting NullPointerException,
can you please suggexst me how i can set the width of the column using that getter value(beanValue)
Thanks

  1. Is it necessary that you use Number instead of int?
  2. Does the Number class has some kind of method to get an integer or a string which you could then convert to an int using Integer.valueOf()?

Make sure your column width field in your bean is not null.

Hi Kim Leppanen !

I need a simple Example Where caption should display before CheckBox.I tried it many way but not able to achieve it.
Thanks

Yes Marius Reinwald,beceause my bean data is setting using BigDecimal from Db,so that i have used Number in my Bean class

I don’t know that much about beans but setColumnWidth seems to require an int instead of a Number so would it not work (or at least not give this exception) when you return columnWidth.intValue() which should return the corresponding int?

yes ,I will return int