How can make Form autoUpdate when the back-bean changes ?

So, i have a form, a Bean item and a Bean


Form form = new Form()
Event nextEvent = getService().getNextEvent() // this is the back bean
BeanItem<Event> eventItem = new BeanItem<Event>(nextEvent)
form.setItemDataSource eventItem

and it gaves me a good form

Type of Event : ________
Date1 : ________
Date2 : ________

But in same cases, behind the scenes the Event bean does this


public void setDate1(Date aDate){
	if("xxxx" == typeOfEvent ){			
		date2 = aDate
	} 
	date1 = aDate
}

So, the bean changes its state. If i save the bean or show it elsewhere it has the correct data, but i can´t make the form to show the change.
As the bean it is not tied to the view, i can´t raise a changeValue event to de Fields to re read the bean.

What option do i have ?

Hi,

You basically have two options. The first is to not call setDate1(xxx) on your bean, but call myBeanItem.getItemProperty(“date1”).setValue(xxx). Calling through the item wrapping the bean will fire an event to the form, which will cause the form to automatically refresh the value.

The other option is to build an alternative notification system yourself. So that each time setDate1(xxx) is called, you also trigger relevant fields / forms to redraw themselves.

Both methods have their drawbacks, but I’d say the cleaner way is the first one I described. The code can become a bit uglier as you actually need a reference to the item instead of a reference to the bean.

HTH,
/Jonatan

Just noting that there’s
an example
of implementing a value change notification mechanism for a bean.

The first suggested method (calling setValue() through the BeanItem wrapper) is much easier though.

Very nice example.
I know, using the BeanItem Wrapper its easy, but the set value begins in a bussines rule in the bean. I dont wanna mix it in the presentation logic.

I’ll try the way the example does

Thanks