FormBinder not updating new datasource

Hi All,

I’m having an issue with the FormBinder addon. It seems to work fine when the code is as described in the sample code as follows:


NotificationForm theForm = new NotificationForm();
form = new ViewBoundForm(theForm)
//Create POGO and load into the form
Notification testNotification = new Notification(summary:"Testing 123")
form.setItemDataSource(new BeanItem<Notification>(testNotification))

//Works and Test123 is shown in the form

The problem is however, this form is populated by the user selecting an item and the form is populated. So I have a method that is called to call form.setItemDataSource with the new datasource. This part is not working.


//Set the DataSource for the item to be displayed
public void updateDataSource(BeanItem<Notification> newDataSource){
		if(newDataSource!=null){
			log.debug("Setting Datasource: ${newDataSource}");
			form.setItemDataSource(newDataSource);
			notification = (Notification)((BeanItem)newDataSource).getBean();
			form.setEnabled(true);
			//notificationAttachments.setParentItem(notification);
			form.getFooter().setEnabled(true);
			log.debug("Summary Field 1: ${form.getField('summary')?.getValue()}")
		}
		else{
			//Set new objects and readonly the form
			log.debug("Setting DS to readonly")
			form.setItemDataSource(new BeanItem(new Notification()));
			form.setEnabled(false);
		}
		
		if(InsufficientQualificationNotification.class.isAssignableFrom(notification.getClass())){
			form.setReadOnly(true);
		}
		else if(ExpiringQualificationNotification.class.isAssignableFrom(notification.getClass())){
			form.setReadOnly(true);
		}else{
			form.setReadOnly(false);
		}
	}

The form itself is updating, the logs prove that (Summary Field 1 & 2), however the screen is not updating with the new data.

Just to add some extra fun into the mix, the form.readOnly / enabled parts of the code works fine.

Things to note: this code all works fine with “standard” forms - so all that has changed is the ViewBoundForm.
If I update the summary field and save the record, the “new” record is updated. If my FormBinder has multiple fields (not shown here for simplicity) only the changed fields on the form are saved, the rest of the bean is kept in tact.

Is this something funny with the ViewBoundForm i’m missing?

~Ben

Hi,

Could you provide a (reduced) standalone example application of your problem? It would be much easier to check out what is the problem and fix it.

cheers,
matti

Hi Matti,

I’ll look into a stand alone version at for you, in the mean time, here is a simpler method that doesn’t work.

FYI, this code works fine if the form is a normal form, so i’m just wondering what is different for ViewBoundForm vs normal Form.


public void updateDataSource(BeanItem<Notification> newDataSource){
		form.setItemDataSource(newDataSource);
}

Just an update on this. In my standalone test application the setItemDataSource seems fine - it just doesn’t work in my production application.

Any ideas why a form would have the backing bean connected when logged with form.getField(‘name’).getValue() but would be displayed on screen as a blank field? I have no idea whats not right here.

Thanks,
~Ben

Hi,

Do you have an other thread (non user initiated) in you production system that updates the item in the Form? Will browser reload make the new item appear?

cheers,
matti

Hi Matti,

As far as I’m aware, I don’t have an additional thread - in other words, i’m not creating a new thread, BUT refreshing the page does populate the data.

Basically the application flow goes like this:

  1. User selects object from a drop down (BeanItemContainer backed).
  2. Selected object is refreshed into current hibernate context
  3. SetItemDataSource() is called on the form, with the refreshed bean.

Where do we go from here?

Hi Matti,

I’ve got this fixed. It all had something to do with the way hibernate was re-attaching objects to the session context, perhaps it was using its own thread behind the scenes. I’m doing the re-attach in a different way (I was fixing another issue) and it resolved this problem.

PS: Apart from this issue i’ve had, this plugin will save me so much time designing more complex layouts. Thanks for your work on it.

~Ben

Hmm, so I’m once again stuck with this issue, none of the forms are updating.

I’ve looked at tracing and the threading issue, and everything seems to be happening on the one thread.

From what I can see, the form is updating, the field itself is updating, however the layout doesn’t seem to be updating on screen (potentially a repaint issue).

I’ve attempted to repaint the form, the layout, as well as all the containers above the form and the layout to no avail.

I have no idea what i’m missing here??

~Ben

Hi,

Don’t know exactly what is the issue in your case, but one thing to note: If the property of a field remains the same, field don’t go magically re-reading to value from the backed bean if its value is changed. Fields do update their values only if the property fires a Property.ValueChangeEvent.

Don’t know exactly what is the problem in you case. It is hard to do debugging only via forum :-). I have one suggestion to you: switch from Hibernate to EclipseLink. It is much better suited for stateful apps. You’ll save yourself from a lot of head aches.

cheers,
matti

Hi Matti,

Thanks for the tip on eclipse link. I’ll see if i can wire that into grails. Hibernate has given me a lot of grief in this project - although recently I got my container playing ball and doing session attachment/detachment properly.

I understand that if the value of the item property doesn’t change, the field won’t update, but form.setItemDataSource(newDataSource) should update all properties in the Item right??

The code works fine when the page is rendered for the first time (the bean is displayed in the form), but upon changing the datasource, the form does not update. Interestingly enough, part of the changing datasource involves making the form disabled if the datasource is null - and this code works fine when a null selection is made. So i’m really just a bit confused where to look as the fields seem to be repainting for enabled/disabled but not for the new data.

The only other 2 differences between my production app and the test app, is on production the form is nested inside panels and layouts. Also the test project is java and the production app is grails.

Is there anything there I should be aware of that could be causing these updates to not happen?

Thanks for all your help!

~Ben

If you are trying to re-assign the same property instance I wouldn’t be surprised if there was an optimization to bypass updates. Setting the data source to null in the between should force the update.

If you can build a test up that fails reliably I can see if this is a FormBinder issue or something else.

cheers,
matti

Hi Matti,

I’m in the process of doing this, and so far the plugin is working just fine in my test grails environment, so something must be different with my application somehow. I just have to find the right place to look.

Here is some more info though. When i change value, the new values are reported in the UIDL response (via firebug), they are just not rendered.

However when looking at the debug window, the “working” test shows the “variables” in the response tree, but the “not working” version does not show the “variables” in the response tree.

Not Working Version (Address Field)

Firebug Response (cut out other fields etc)

["16",{"id": "PID38","width": "200px","caption": "Address","v":{"text":"Test 2"}}]

Working Version (Summary Field)

Firebug Response (cut out other fields etc)

["10",{"id": "PID44","width": "100.0%","caption": "Summary","v":{"text":"Test 2"}}]

~Ben

[quote=Ben Lewis
However when looking at the debug window, the “working” test shows the “variables” in the response tree, but the “not working” version does not show the “variables” in the response tree.

[/quote]

Hi,

That sounds like a regression in 6.7.0. You should update your Vaadin version. In the other test (based on screenshot) you are using 6.6 or older.

cheers,
matti

Hey Matti,

I’ve got around to recompiling the widgetset (not the easiest thing to do in a grails project) and I can confirm FormBinder is now working! It seems that even though I was running 6.7.0+ as my vaadin jar, I had an older version compiled into the widgetset, so updating this fixed it.

Thanks for you help!

~Ben