Community
Participate
Working Groups
The purpose of this task is to trace the work-progress on the data binding with Spring. Precisely, it should deals with the Declarative data binding in XWT with Spring service declaration.
Yves, If I understand your idea you mean manage XWT DataContext with Spring bean declaration? Is that? For instance today you can write : --------------------------------------------------------------------- <Shell xmlns="http://www.eclipse.org/xwt/presentation" xmlns:x="http://www.eclipse.org/xwt" xmlns:y="clr-namespace:org.eclipse.e4.xwt.tests.databinding" DataContext="{StaticResource myData}"> <Shell.Resources> <y:Person x:Key="myData"/> </Shell.Resources> --------------------------------------------------------------------- S I suppose you wish declare myData as Spring bean : --------------------------------------------------------------------- <bean id="myData" class="org.eclipse.e4.xwt.tests.databinding.Person" /> --------------------------------------------------------------------- and use it in XWT file like this : --------------------------------------------------------------------- <Shell xmlns="http://www.eclipse.org/xwt/presentation" xmlns:x="http://www.eclipse.org/xwt" DataContext="{MySpringResource myData}"> --------------------------------------------------------------------- Where MySpringResource is Spring ApplicationContext and myData a Spring bean. Or perhaps use SpringCLRFactory: --------------------------------------------------------------------- <Shell xmlns="http://www.eclipse.org/xwt/presentation" xmlns:x="http://www.eclipse.org/xwt" x:ClassFactory="MySpringCLRFactory bean=myUI dataContext=myData"> --------------------------------------------------------------------- BUT IMHO I don't know if it's good idea to do declare DataContext as Spring bean or with XWT with Shell.Resources. Indeed in real life application you wish manage CRUD (Create-Read-Update-Delete) Form page. The logic of the Form page (CLR) (validate required fields) are the same for Create-Update for instance. So in my case I will have one CLR + one XWT file to manage Create-Read-Update. Switch the mode (Create-Read-Update) I will link my DataContext with person wich comes from : * Create mode : create an instance of Person. * Read-Update mode : load a person (by personId) with a service. So I will do : ------------------------------------------------------------------ Long personID = ... Person person = null; if (personID == null) { person = new Person(); // or even call myService.createPerson(); } else { person = myService.loadPerson(personID); } XWT.open("CRUPerson.xwt", person); ------------------------------------------------------------------ But better I will prefer manage DataContext in the CLR. So I will prefer write : ------------------------------------------------------------------ Long personID = ... XWT.open("CRUPerson.xwt", personID); ------------------------------------------------------------------ Define Loaded event on the Shell : --------------------------------------------------------------------- <Shell xmlns="http://www.eclipse.org/xwt/presentation" xmlns:x="http://www.eclipse.org/xwt" x:Class="ui.CRUPerson" Loaded="init" --------------------------------------------------------------------- And manage the DataContext on the ui.CRUPerson#Init(Event e) : public CRUPerson { public void init(Event e) { Long personID = (Long)UserData.getDataContext(e.widget); if (personID == null) { person = new Person(); // or even call myService.createPerson(); } else { person = myService.loadPerson(personID); } UserData.setDataContext(event.widget, person); } } With that I can manage display errors on init method. I don't know if my idea works, but I wish do like this (it looks like WPF Form Page)
It was done for a while.