Hi Isomorphic,
please take a look at this test case.
For datasource "animals", LocaleMessageProvider is never called.
For datasource "employees" works as expected.
(SNAPSHOT_v12.1d_2018-11-12/PowerEdition Deployment (built 2018-11-12))
animals.ds.xml
employees.ds.xml
BuiltInDS.java
Best regards
Pavo
please take a look at this test case.
For datasource "animals", LocaleMessageProvider is never called.
For datasource "employees" works as expected.
(SNAPSHOT_v12.1d_2018-11-12/PowerEdition Deployment (built 2018-11-12))
Code:
<servlet>
<servlet-name>RegisterDS</servlet-name>
<servlet-class>com.smartgwt.sample.server.listener.RegisterDS</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
Code:
package com.smartgwt.sample.server.listener;
import java.util.Locale;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import com.isomorphic.datasource.DSRequest;
import com.isomorphic.datasource.DataSource;
import com.isomorphic.datasource.DynamicDSGenerator;
import com.isomorphic.util.LocaleMessageProvider;
import com.isomorphic.util.LocaleMessageProviderRegistry;
import com.isomorphic.util.LocaleMessageSourceEnum;
public class RegisterDS extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
public void init() throws ServletException {
final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DynamicDSGenerator datasourceGenerator = new DynamicDSGenerator() {
@Override
public DataSource getDataSource(String id, DSRequest arg1) {
try {
if (id.startsWith("animals")) {
ServletContext servletContext = getServletContext();
String strAbsolutePath = servletContext.getRealPath("ds");
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document doc = documentBuilder.parse(strAbsolutePath + "\\" + id + ".ds.xml");
return DataSource.fromXML(doc);
} else if (id.startsWith("employees")) {
return null;
}
} catch (Exception e) {
}
return null;
}
};
LocaleMessageProvider localeMessageProvider = new LocaleMessageProvider() {
@Override
public String getMessage(String arg0, Locale arg1, String arg2, String arg3, LocaleMessageSourceEnum arg4, String arg5) {
String id = arg0;
try {
return id + "translation";
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
};
LocaleMessageProviderRegistry.addDSLocaleMessageProvider(localeMessageProvider);
DataSource.addDynamicDSGenerator(datasourceGenerator);
}
}
Code:
<field name="information" title="Interesting Facts" type="text" length="1000">
<title><fmt:message key="title"/></title>
</field>
Code:
<field name="EmployeeStatus" title="Status" type="text" length="40">
<title><fmt:message key="title"/></title>
</field>
Code:
ListGrid lg1 = new ListGrid() {
{
setDataSource("animals");
ListGridField informationLGF = new ListGridField("information");
setFields(informationLGF);
fetchData();
}
};
ListGrid lg2 = new ListGrid() {
{
setDataSource("employees");
ListGridField employeeStatusLGF = new ListGridField("EmployeeStatus");
setFields(employeeStatusLGF);
fetchData();
}
};
addItem(lg1);
addItem(lg2);
Pavo
Comment