I am using gwt 2.4, smartgwt 3.1d EE, IE 9, Java 1.7 and Eclipse indigo
The scenario:
The website will cater to different companies.
Each company will have its own database.
But each database's structure is identical, only the actual contained data will differ.
I saw some one ask same question before and he use DynamicDSGenerator solve his problem. I want to do the same thing like him. Here is the link for that tread:
http://forums.smartclient.com/showthread.php?t=15937
But I have some question not very clear, please gave me the instruction.
1. How do I modify my project.html file?
Do I still need
" <script src="sc/DataSourceLoader?dataSource=dbName_mydbname_mydatasourceDS"></script> "
in my html file?
if yes, the datasource name should just put regular name like "mydatasourceDS"
or have to be full name like
"dbName_mydbname_mydatasourceDS"?
2. How do I modify my web.xml file?
I create a MyDSLoaderServlet, So Do I still need keep this
<servlet-name>DataSourceLoader</servlet-name>
<servlet-class>com.isomorphic.servlet.DataSourceLoader</servlet-class>
in my web.xml file?
Or I need replace it to
<servlet-name>DataSourceLoader</servlet-name>
<servlet-class>MyDSLoaderServlet</servlet-class>
Or I need keep orignal one and create a new servlet-name in web.xml file?
3. In MyDSLoaderServlet, my doGet() like this
My questions are:
a. does this:
DataSource.addDynamicDSGenerator(new TriadDSGenerator(), dbName);
correct to put here like this?
b. After I got my ds, I think I need send it back to client side through HttpServletResponse, Am I right?
If I am correct, then how can I set my ds in response?
4. On client side, how to use DataSource.load()?
My regular code like this:
This way the ds will load at application start by project.html file.
Now I want to load my datasource dynamic, So I change my code like this:
But looks this code not correct, because in Console log, I saw this:
[WARN] 404 - GET /myproject/sc/DataSourceLoader?dataSource=dbName_myDbName_myDataSourceDS&isc_rpc=1&isc_v=SNAPSHOT_v8.3d_2012-07-23&isc_xhr=1&isc_tnum=0&_transaction=%3Ctransaction%20xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2F10%2FXMLSchema-instance%22%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3CtransactionNum%20xsi%3Atype%3D%22xsd%3Along%22%3E0%3C%2FtransactionNum%3E%3Coperations%20xsi%3Atype%3D%22xsd%3AList%22%3E%3Celem%3E__ISC_NULL__%3C%2Felem%3E%3C%2Foperations%3E%3C%2Ftransaction%3E&protocolVersion=1.0 (127.0.0.1) 1413 bytes
Request headers
Accept: */*
Accept-Language: en-US,zh-CN;q=0.7,zh-TW;q=0.3
Referer: http://127.0.0.1:8888/Triad40.html?gwt.codesvr=127.0.0.1:9997
UA-CPU: AMD64
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Host: 127.0.0.1:8888
Connection: Keep-Alive
Cookie: isc_cState=ready
Response headers
X-Included-Test2: true
X-Included-Test: true
Content-Type: text/html; charset=iso-8859-1
Content-Length: 1413
And in Development Mode log, I saw:
NullPointerException:null error at " lg.setDataSource(ds);"
So please tell me the correct way to use DataSource.load()?
The scenario:
The website will cater to different companies.
Each company will have its own database.
But each database's structure is identical, only the actual contained data will differ.
I saw some one ask same question before and he use DynamicDSGenerator solve his problem. I want to do the same thing like him. Here is the link for that tread:
http://forums.smartclient.com/showthread.php?t=15937
But I have some question not very clear, please gave me the instruction.
1. How do I modify my project.html file?
Do I still need
" <script src="sc/DataSourceLoader?dataSource=dbName_mydbname_mydatasourceDS"></script> "
in my html file?
if yes, the datasource name should just put regular name like "mydatasourceDS"
or have to be full name like
"dbName_mydbname_mydatasourceDS"?
2. How do I modify my web.xml file?
I create a MyDSLoaderServlet, So Do I still need keep this
<servlet-name>DataSourceLoader</servlet-name>
<servlet-class>com.isomorphic.servlet.DataSourceLoader</servlet-class>
in my web.xml file?
Or I need replace it to
<servlet-name>DataSourceLoader</servlet-name>
<servlet-class>MyDSLoaderServlet</servlet-class>
Or I need keep orignal one and create a new servlet-name in web.xml file?
3. In MyDSLoaderServlet, my doGet() like this
Code:
public void doGet(HttpServletRequest req, HttpServletResponse res) { String id = req.getParameter("dataSource"); //Does this scrrect? DataSource.addDynamicDSGenerator(new MyDSGenerator(), dbName); if (null != id) System.out.println("passed datasource ID is :" + id + ":" + this); else System.out.println("passed datasource ID is null" + this); MyDSGenerator tds = new MyDSGenerator(); DataSource ds = tds.getDataSource(id, new DSRequest()); // need send ds back? then how? }
a. does this:
DataSource.addDynamicDSGenerator(new TriadDSGenerator(), dbName);
correct to put here like this?
b. After I got my ds, I think I need send it back to client side through HttpServletResponse, Am I right?
If I am correct, then how can I set my ds in response?
4. On client side, how to use DataSource.load()?
My regular code like this:
Code:
ListGrid lg = new ListGrid(); lg.setWidth100(); lg.setHeight100(); DataSource ds = DataSource.getDataSource("myDataSourceDS"); lg.setDataSource(ds); lg.fetchData()
Now I want to load my datasource dynamic, So I change my code like this:
Code:
Function func = new Function() { @Override public void execute() { System.out.println("### DS load complete"); } }; DataSource.load("dbName_myDbName_myDataSourceDS", func, true); ListGrid lg = new ListGrid(); lg.setWidth100(); lg.setHeight100(); DataSource ds = DataSource.getDataSource("myDataSourceDS"); lg.setDataSource(ds); lg.fetchData()
[WARN] 404 - GET /myproject/sc/DataSourceLoader?dataSource=dbName_myDbName_myDataSourceDS&isc_rpc=1&isc_v=SNAPSHOT_v8.3d_2012-07-23&isc_xhr=1&isc_tnum=0&_transaction=%3Ctransaction%20xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2F10%2FXMLSchema-instance%22%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3CtransactionNum%20xsi%3Atype%3D%22xsd%3Along%22%3E0%3C%2FtransactionNum%3E%3Coperations%20xsi%3Atype%3D%22xsd%3AList%22%3E%3Celem%3E__ISC_NULL__%3C%2Felem%3E%3C%2Foperations%3E%3C%2Ftransaction%3E&protocolVersion=1.0 (127.0.0.1) 1413 bytes
Request headers
Accept: */*
Accept-Language: en-US,zh-CN;q=0.7,zh-TW;q=0.3
Referer: http://127.0.0.1:8888/Triad40.html?gwt.codesvr=127.0.0.1:9997
UA-CPU: AMD64
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Host: 127.0.0.1:8888
Connection: Keep-Alive
Cookie: isc_cState=ready
Response headers
X-Included-Test2: true
X-Included-Test: true
Content-Type: text/html; charset=iso-8859-1
Content-Length: 1413
And in Development Mode log, I saw:
NullPointerException:null error at " lg.setDataSource(ds);"
So please tell me the correct way to use DataSource.load()?
Comment