Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 322937 - [SpringDM] Data binding management
Summary: [SpringDM] Data binding management
Status: CLOSED FIXED
Alias: None
Product: XWT
Classification: Technology
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-17 13:32 EDT by Yves YANG CLA
Modified: 2013-01-24 15:31 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yves YANG CLA 2010-08-17 13:32:39 EDT
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.
Comment 1 Angelo ZERR CLA 2010-08-17 22:52:58 EDT
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)
Comment 2 Yves YANG CLA 2013-01-13 17:48:55 EST
It was done for a while.