2

Sorry in case this question has already been asked, but after searching these topics still could not figure out the problem.

I have very simple bean as below,

<code>
    public class FileBean extends AbstractFileBean {
    ...
    private int headingRow = 0;
    private ColumnDefinition columnSet;
    ...
}
</code>

Now using above bean, am trying to bind these properties to UI fields as below.

<code>
    public AddCsv(AbstractFileBean fileBean) {
    csvbinder = new BeanFieldGroup<FileBean>(FileBean.class);
    csvbinder.setItemDataSource((FileBean) fileBean);
    csvbinder.setBuffered(false);
    csvbinder.bind((TextField)form.getField(UIField.NAME), "name");
    csvbinder.bind((IntStepper)form.getField(UIField.HEADINGROW), "headingRow");
    ComboBox columnDefinitions = (ComboBox)form.getField(UIField.COLUMNDEF);
    csvbinder.bind(columnDefinitions, "columnSet");
    //AddFileUtil.populateColumnSets(columnDefinitions,fileBean); - this method fills up     combo box
    ...
}
</code>

Problem: I have one form with set of fields as described above. There is another button on same form as 'Upload New file', which basically picks up the file from system and I'm setting name and path as below by service layer

<code>
    fileBean.setName(file.getName());
    fileBean.setFilePath(filePath);
</code> 

After selecting the file, coming back to same form does not show the UI fields populated. The strange thing is, when you type manually in those form fields say inside Name textfield, that is populated inside the filebean. but the only problem is other way round. After selecting the file. Those UI fields still shows as blank.

Is there something missing whilst setting up the binder which is not letting the UI to refresh?

Please let me know in case more information needed.

Thanks in advance,

JustK
  • 23
  • 3

1 Answers1

4

You need to update your BeanItem<FileBean> not your Bean because otherwise noone would actually notice the change.

BeanItem<FileBean> item = csvbinder.getItemDataSource();
item.getItemProperty("name").setValue(file.getName());
item.getItemProperty("filePath").setValue(filePath);
nexus
  • 2,937
  • 3
  • 17
  • 22
  • Thanks @nexus, I was under impression that, the way csvbinder.setItemDataSource((FileBean) fileBean) automatically wraps up the bean and associate with beanItem itself probably it will do the same if i set the value in the bean. Of course that understanding was wrong.I will give a try with your suggestion and keep it updated. – JustK May 19 '14 at 23:12
  • 2
    There is a brand new Webcast explaining the FieldGroup stuff https://www.youtube.com/watch?v=aq_OXCVqvFI&list=TLoi6eHTAH0EUyWsr-9YMD_sB6NQKoEO1W – André Schild May 20 '14 at 09:00