1. SmartClient Version: SNAPSHOT_v9.1d_2014-01-14/LGPL Development Only (built 2014-01-14)
2. Firefox 26.0
3.
4.
5.
6. sample code if applicable
This is just slightly modified showcase "ExcelToGridSample":
in CountryXmlDS.class countryCodeField.setValueXPath("countryCode/code")
in country.data.xml <countryCode><code>XX</code></countryCode>
EntryPoint:
CountryXmlDS:
country.data:
Select any cell in Country column and paste changed value - it works and changed value is indicated in blue.
Now select any cell in Code column and paste changed value - this is NOT working.
The problem lays in datasource.recordsFromText() method, backed with JavaScript function with the same name. That one is using dataSource.validateJSONRecord(). Unfortunately it tries to process as follows:
validateJSONRecord : function (record) {
...
if (field.valueXPath) {
fieldValue = isc.xml.selectObjects(record, field.valueXPath, true);
} else {
fieldValue = record[fieldName];
}
and finds always "undef" value in case of valueXPath field.
MichalG
2. Firefox 26.0
3.
4.
5.
6. sample code if applicable
This is just slightly modified showcase "ExcelToGridSample":
in CountryXmlDS.class countryCodeField.setValueXPath("countryCode/code")
in country.data.xml <countryCode><code>XX</code></countryCode>
EntryPoint:
Code:
package pl.com.tech4.client; import java.util.ArrayList; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.DOM; import com.smartgwt.client.data.Record; import com.smartgwt.client.data.RecordList; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.data.TextImportSettings; import com.smartgwt.client.data.DSCallback; import com.smartgwt.client.data.DSRequest; import com.smartgwt.client.data.DSResponse; import com.smartgwt.client.types.Autofit; import com.smartgwt.client.types.Alignment; import com.smartgwt.client.types.Visibility; import com.smartgwt.client.types.EscapingMode; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Button; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Dialog; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.grid.ListGridRecord; import com.smartgwt.client.widgets.grid.CellSelection; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.form.fields.FormItem; import com.smartgwt.client.widgets.form.fields.ButtonItem; import com.smartgwt.client.widgets.form.fields.TextAreaItem; import com.smartgwt.client.widgets.form.fields.StaticTextItem; public class MainEntryPoint implements EntryPoint, ClickHandler { private ListGrid countryList; private class MyDialog extends Dialog implements com.smartgwt.client.widgets.form.fields.events.ClickHandler { private DynamicForm form; private TextAreaItem textArea; public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) { String text = (String) this.textArea.getValue(); MainEntryPoint.this.pasteText(text); this.removeItem(this.form); this.markForDestroy(); this.hide(); }; public MyDialog() { final int WIDTH = 525; final int HEIGHT = 300; final String GUIDANCE = "Press Ctrl-V (Command-V on Mac) or right click (Option-click on Mac) to paste values, then hit \"Apply\""; StaticTextItem label = new StaticTextItem(); label.setName("label"); label.setShowTitle(false); label.setValue(GUIDANCE); TextAreaItem area = new TextAreaItem(); area.setName("textArea"); area.setShowTitle(false); area.setCanEdit(true); area.setHeight("*"); area.setWidth("*"); this.textArea = area; ButtonItem button = new ButtonItem(); button.setName("apply"); button.setAlign(Alignment.CENTER); button.setTitle("Apply"); button.addClickHandler(this); DynamicForm form = new DynamicForm(); form.setNumCols(1); form.setWidth(WIDTH); form.setHeight(HEIGHT); form.setAutoFocus(true); form.setFields(new FormItem[]{ label, this.textArea, button }); this.form = form; this.setAutoSize(true); this.setShowToolbar(false); this.setCanDragReposition(true); this.setTitle("Paste Cells"); this.setShowModalMask(true); this.setIsModal(true); this.addItem(form); } }; public void onClick(ClickEvent event) { this.new MyDialog().draw(); }; private void pasteText(String text) { ArrayList<String> fieldNames = new ArrayList<String>(); int[][] cells = this.countryList.getCellSelection().getSelectedCells(); if (cells.length == 0) { countryList.getCellSelection().selectCell(0, 0); cells = countryList.getCellSelection().getSelectedCells(); } int firstCol = cells[0][1]; ListGridField[] fields = this.countryList.getFields(); for (int col = firstCol; col < fields.length; col++) { fieldNames.add(this.countryList.getFieldName(col)); } TextImportSettings settings = new TextImportSettings(); settings.setFieldList(fieldNames.toArray(new String[0])); settings.setFieldSeparator("\t"); settings.setEscapingMode(EscapingMode.DOUBLE); DataSource dataSource = this.countryList.getDataSource(); Record[] records = dataSource.recordsFromText(text, settings); this.countryList.applyRecordData(new RecordList(records)); }; public void onModuleLoad() { DOM.getElementById("loadingPicture").removeFromParent(); SC.showConsole(); DataSource dataSource = CountryXmlDS.getInstance(); final ListGrid grid = new ListGrid(); grid.setCanEdit(true); grid.setAutoFetchData(true); grid.setCanDragSelect(true); grid.setCanSelectCells(true); grid.setDataSource(dataSource); grid.setAutoFitData(Autofit.VERTICAL); grid.fetchData(null, new DSCallback() { @Override public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) { grid.getCellSelection().selectCell(0, 0); } }); this.countryList = grid; Button button = new Button(); button.setTitle("Paste Cells"); button.addClickHandler(this); VLayout layout = new VLayout(15); layout.setWidth100(); layout.addMember(grid); layout.addMember(button); layout.draw(); } };
Code:
package pl.com.tech4.client; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.data.fields.*; public class CountryXmlDS extends DataSource { private static CountryXmlDS instance = null; public static CountryXmlDS getInstance() { if (instance == null) { instance = new CountryXmlDS("countryDS"); } return instance; } public CountryXmlDS(String id) { setID(id); setRecordXPath("/List/country"); DataSourceIntegerField pkField = new DataSourceIntegerField("pk"); pkField.setHidden(true); pkField.setPrimaryKey(true); DataSourceTextField countryCodeField = new DataSourceTextField("countryCode", "Code"); countryCodeField.setRequired(true); countryCodeField.setValueXPath("countryCode/code"); DataSourceTextField countryNameField = new DataSourceTextField("countryName", "Country"); countryNameField.setRequired(true); DataSourceTextField capitalField = new DataSourceTextField("capital", "Capital"); DataSourceTextField governmentField = new DataSourceTextField("government", "Government", 500); DataSourceBooleanField memberG8Field = new DataSourceBooleanField("member_g8", "G8"); DataSourceTextField continentField = new DataSourceTextField("continent", "Continent"); continentField.setValueMap("Europe", "Asia", "North America", "Australia/Oceania", "South America", "Africa"); DataSourceDateField independenceField = new DataSourceDateField("independence", "Nationhood"); DataSourceFloatField areaField = new DataSourceFloatField("area", "Area (kmē)"); DataSourceIntegerField populationField = new DataSourceIntegerField("population", "Population"); DataSourceFloatField gdpField = new DataSourceFloatField("gdp", "GDP ($M)"); DataSourceLinkField articleField = new DataSourceLinkField("article", "Info"); setFields(pkField, countryCodeField, countryNameField, capitalField, governmentField, memberG8Field, continentField, independenceField, areaField, populationField, gdpField, articleField); setDataURL("country.data.xml"); setClientOnly(true); } }
Code:
<List> <country> <continent>North America</continent> <countryName>United States</countryName> <countryCode> <code>US</code> </countryCode> <area>9631420</area> <population>298444215</population> <gdp>12360000</gdp> <independence>1776-07-04</independence> <government>federal republic</government> <government_desc>2</government_desc> <capital>Washington, DC</capital> <member_g8>true</member_g8> <article>http://en.wikipedia.org/wiki/United_states</article> </country> <country> <continent>Asia</continent> <countryName>China</countryName> <countryCode> <code>CH</code> </countryCode> <area>9596960</area> <population>1313973713</population> <gdp>8859000</gdp> <government>Communist state</government> <government_desc>0</government_desc> <capital>Beijing</capital> <member_g8>false</member_g8> <article>http://en.wikipedia.org/wiki/China</article> </country> <country> <continent>Asia</continent> <countryName>Japan</countryName> <countryCode> <code>JA</code> </countryCode> <area>377835</area> <population>127463611</population> <gdp>4018000</gdp> <government>constitutional monarchy with parliamentary government</government> <government_desc>1</government_desc> <capital>Tokyo</capital> <member_g8>true</member_g8> <article>http://en.wikipedia.org/wiki/Japan</article> </country> <country> <continent>Asia</continent> <countryName>India</countryName> <countryCode> <code>IN</code> </countryCode> <area>3287590</area> <population>1095351995</population> <gdp>3611000</gdp> <independence>1947-08-15</independence> <government>federal republic</government> <government_desc>2</government_desc> <capital>New Delhi</capital> <member_g8>false</member_g8> <article>http://en.wikipedia.org/wiki/India</article> </country> <country> <continent>Europe</continent> <countryName>Germany</countryName> <countryCode> <code>GM</code> </countryCode> <area>357021</area> <population>82422299</population> <gdp>2504000</gdp> <independence>1871-01-18</independence> <government>federal republic</government> <government_desc>2</government_desc> <capital>Berlin</capital> <member_g8>true</member_g8> <article>http://en.wikipedia.org/wiki/Germany</article> </country> <country> <continent>Europe</continent> <countryName>United Kingdom</countryName> <countryCode> <code>UK</code> </countryCode> <area>244820</area> <population>60609153</population> <gdp>1830000</gdp> <independence>1801-01-01</independence> <government>constitutional monarchy</government> <government_desc>1</government_desc> <capital>London</capital> <member_g8>true</member_g8> <article>http://en.wikipedia.org/wiki/United_kingdom</article> </country> <country> <continent>Europe</continent> <countryName>France</countryName> <countryCode> <code>FR</code> </countryCode> <area>547030</area> <population>60876136</population> <gdp>1816000</gdp> <government>republic</government> <government_desc>5</government_desc> <capital>Paris</capital> <member_g8>true</member_g8> <article>http://en.wikipedia.org/wiki/France</article> </country> <country> <continent>Europe</continent> <countryName>Italy</countryName> <countryCode> <code>IT</code> </countryCode> <area>301230</area> <population>58133509</population> <gdp>1698000</gdp> <independence>1861-03-17</independence> <government>republic</government> <government_desc>5</government_desc> <capital>Rome</capital> <member_g8>true</member_g8> <article>http://en.wikipedia.org/wiki/Italy</article> </country> <country> <continent>Asia</continent> <countryName>Russia</countryName> <countryCode> <code>RS</code> </countryCode> <area>17075200</area> <population>142893540</population> <gdp>1589000</gdp> <independence>1991-08-24</independence> <government>federation</government> <government_desc>3</government_desc> <capital>Moscow</capital> <member_g8>true</member_g8> <article>http://en.wikipedia.org/wiki/Russia</article> </country> <country> <continent>South America</continent> <countryName>Brazil</countryName> <countryCode> <code>BR</code> </countryCode> <area>8511965</area> <population>188078227</population> <gdp>1556000</gdp> <independence>1822-09-07</independence> <government>federative republic</government> <government_desc>3</government_desc> <capital>Brasilia</capital> <member_g8>false</member_g8> <article>http://en.wikipedia.org/wiki/Brazil</article> </country> <country> <continent>North America</continent> <countryName>Canada</countryName> <countryCode> <code>CA</code> </countryCode> <area>9984670</area> <population>33098932</population> <gdp>1114000</gdp> <independence>1867-07-01</independence> <government>constitutional monarchy with parliamentary democracy and federation</government> <government_desc>1</government_desc> <capital>Ottawa</capital> <member_g8>true</member_g8> <article>http://en.wikipedia.org/wiki/Canada</article> </country> <country> <continent>North America</continent> <countryName>Mexico</countryName> <countryCode> <code>MX</code> </countryCode> <area>1972550</area> <population>107449525</population> <gdp>1067000</gdp> <independence>1810-09-16</independence> <government>federal republic</government> <government_desc>2</government_desc> <capital>Mexico (Distrito Federal)</capital> <member_g8>false</member_g8> <article>http://en.wikipedia.org/wiki/Mexico</article> </country> <country> <continent>Europe</continent> <countryName>Spain</countryName> <countryCode> <code>SP</code> </countryCode> <area>504782</area> <population>40397842</population> <gdp>1029000</gdp> <independence>1492-01-01</independence> <government>parliamentary monarchy</government> <government_desc>4</government_desc> <capital>Madrid</capital> <member_g8>false</member_g8> <article>http://en.wikipedia.org/wiki/Spain</article> </country> <country> <continent>Asia</continent> <countryName>South Korea</countryName> <countryCode> <code>KS</code> </countryCode> <area>98480</area> <population>48846823</population> <gdp>965300</gdp> <independence>1945-08-15</independence> <government>republic</government> <government_desc>5</government_desc> <capital>Seoul</capital> <member_g8>false</member_g8> <article>http://en.wikipedia.org/wiki/South_korea</article> </country> <country> <continent>Asia</continent> <countryName>Indonesia</countryName> <countryCode> <code>ID</code> </countryCode> <area>1919440</area> <population>245452739</population> <gdp>865600</gdp> <independence>1945-08-17</independence> <government>republic</government> <government_desc>5</government_desc> <capital>Jakarta</capital> <member_g8>false</member_g8> <article>http://en.wikipedia.org/wiki/Indonesia</article> </country> </List>
Now select any cell in Code column and paste changed value - this is NOT working.
The problem lays in datasource.recordsFromText() method, backed with JavaScript function with the same name. That one is using dataSource.validateJSONRecord(). Unfortunately it tries to process as follows:
validateJSONRecord : function (record) {
...
if (field.valueXPath) {
fieldValue = isc.xml.selectObjects(record, field.valueXPath, true);
} else {
fieldValue = record[fieldName];
}
and finds always "undef" value in case of valueXPath field.
MichalG
Comment