Hi Isomorphic,
please see this testcase where I use addToTemplateContext() with isSnippet:true, as you suggest here.
I'd expect to see in my mail body "Anteater - Not Endangered", like I do with commented out
in animals.ds.xml. Instead I get "$commonName - $status". I believe this is a bug (using v11.1p_2018-02-27).
animals.ds.xml:
MySQLDataSource.java:
Call the sample with ARC (Advanced REST Client Addon in Chrome) and this data:
URL: http://127.0.0.1:8888/builtinds/sc/RESTHandler
Body:
My use case is that I want to pass DB content here with addToTemplateContext() instead of using <templateFile>.
The DB content will be the file content at start, but then every tenant can modify this.
This is an important one for me.
Best regards
Blama
As enhancement:
It would be even more easy for me if <messageTemplate> supported something like <messageTemplate isSnippet=true> - Then I would not even need to change my SQLDataSource-subclass, as I can easily get the DB content with my existing custom-Velocity variables.
please see this testcase where I use addToTemplateContext() with isSnippet:true, as you suggest here.
I'd expect to see in my mail body "Anteater - Not Endangered", like I do with commented out
Code:
<!-- <messageTemplate>$commonName - $status</messageTemplate> -->
animals.ds.xml:
Code:
<DataSource
ID="animals"
serverType="sql"
tableName="animals"
testFileName="animals.data.xml" serverConstructor="com.smartgwt.sample.server.listener.MySQLDataSource">
<fields>
<field name="commonName" title="Animal" type="text"/>
<field name="scientificName" title="Scientific Name" type="text" primaryKey="true" required="true"/>
<field name="lifeSpan" title="Life Span" type="integer"/>
<field name="status" title="Endangered Status" type="text">
<valueMap>
<value>Threatened</value>
<value>Endangered</value>
<value>Not Endangered</value>
<value>Not currently listed</value>
<value>May become threatened</value>
<value>Protected</value>
</valueMap>
</field>
<field name="diet" title="Diet" type="text"/>
<field name="information" title="Interesting Facts" type="text" length="1000"/>
<field name="picture" title="Picture" type="image" detail="true"
imageURLPrefix="/isomorphic/system/reference/inlineExamples/tiles/images/"/>
</fields>
<operationBindings>
<!-- Server operationBindings -->
<operationBinding operationType="fetch">
<mail contentType="text/html">
<from>[B]your server mail address[/B]</from>
<to>[B]your user mail account[/B]</to>
<subject>TESTMAIL</subject>
<messageTemplate>$test</messageTemplate>
<!-- <messageTemplate>$commonName - $status</messageTemplate> -->
</mail>
<criteria fieldName="commonName" operator="equals" value="Anteater" />
</operationBinding>
</operationBindings>
</DataSource>
Code:
package com.smartgwt.sample.server.listener;
import com.isomorphic.datasource.DSRequest;
import com.isomorphic.datasource.DSResponse;
import com.isomorphic.sql.SQLDataSource;
public class MySQLDataSource extends SQLDataSource {
private static final long serialVersionUID = -2103887355803373948L;
@Override
public DSResponse executeFetch(DSRequest request) throws Exception {
[B]request.addToTemplateContext("test", "$commonName - $status", true);[/B]
return super.executeFetch(request);
}
}
URL: http://127.0.0.1:8888/builtinds/sc/RESTHandler
Body:
Code:
<request>
<dataSource>animals</dataSource>
<operationType>fetch</operationType>
</request>
The DB content will be the file content at start, but then every tenant can modify this.
This is an important one for me.
Best regards
Blama
As enhancement:
It would be even more easy for me if <messageTemplate> supported something like <messageTemplate isSnippet=true> - Then I would not even need to change my SQLDataSource-subclass, as I can easily get the DB content with my existing custom-Velocity variables.
Comment