I am all confused wid multiple Datasources. I have read through all the threads mentioned in the forum relative to this topic. The most explanatory ones were:
http://forums.smartclient.com/showpo...83&postcount=6
http://forums.smartclient.com/showthread.php?t=4775
http://forums.smartclient.com/showthread.php?t=4739
After a lot of trial and error am able to get multiple elements to be displayed on the grid. But not their values. They appear as [object Object] comma seperated values.
XML structure I am using:
<Root protocol="tcp" name="DC:2">
<ExtendedLanguage>
<Flow direction="target-server" state="established"/>
<Match match-order="0">
<ExtendedPattern type="binary" pattern="/e/e/e"/>
</Match>
<Match match-order="1">
<PayloadTest relative-to-previous="yes" num-bytes="4" />
</Match>
<Match match-order="2">
<PCRE present="yes" num-bytes="4" />
</Match>
</ExtendedLanguage>
<EventGroup>Dummy 1</EventGroup>
<EventGroup>Dummy 2</EventGroup>
<Description><![CDATA[This is for a test]]></Description>
<Reference name="URLREF"><![CDATA[http://www.microsoft.com]]> </Reference>
<Reference name="CVE" value="CVE"/>
</Root>
Like you can see I have a nested structure present in the data:
For starters I wrote define a RootDS which deals wid Root node and its related attributes. All ValueXPaths by default give me 1st Element in case of multiple element structures.
for eg: //Root/ExtendedLanguage/Match/@match-order gives me value 0. What I needed was some way to show all 3 values in the grid.
I created the following datasources:
Like suggested for nested elements I created another datasource ExtendedLanguageDS and used this line instead of the one above **:
matchField.setTypeasDataSource(ExtendedLanguageDS.getInstance());
This has no apparent difference since no matter what fields I put in this datasource they have no effect on the first one.
So what I concluded from this was when the Xpath //Root/ExtendedLanguage/Match is fired, I get the match elements as JS Objs from the server (which in my case is coming from eixstDB via restlets).
If on the matchField if I setTypeAsDataSource it allows me to say that it belongs to another datasource ==> its nested.
I have a few questions on this and let me tell you that I have not understood datasources completely.
1) Why are the fields in the second datasource absolutely redundant?
2) How shud I get the attribute values for eg: match-order or pattern coz it seems setChildTagName can only get values of Elements. for eg: I was able to get DUMMY1 and DUMMY2 to be displayed in the grid coz they are in the structure <EventGroup>value</EventGroup>
3) Incase of ExtendedLanguage where match Elements inturn consists of different elements like PCRE, ExtendedPattern, how should its Datasource be defined so that all the elements are recognized.
I would highly appreciate any help on this since I spent 4 days and really havent got through anything.
Thanks,
Hetal
http://forums.smartclient.com/showpo...83&postcount=6
http://forums.smartclient.com/showthread.php?t=4775
http://forums.smartclient.com/showthread.php?t=4739
After a lot of trial and error am able to get multiple elements to be displayed on the grid. But not their values. They appear as [object Object] comma seperated values.
XML structure I am using:
<Root protocol="tcp" name="DC:2">
<ExtendedLanguage>
<Flow direction="target-server" state="established"/>
<Match match-order="0">
<ExtendedPattern type="binary" pattern="/e/e/e"/>
</Match>
<Match match-order="1">
<PayloadTest relative-to-previous="yes" num-bytes="4" />
</Match>
<Match match-order="2">
<PCRE present="yes" num-bytes="4" />
</Match>
</ExtendedLanguage>
<EventGroup>Dummy 1</EventGroup>
<EventGroup>Dummy 2</EventGroup>
<Description><![CDATA[This is for a test]]></Description>
<Reference name="URLREF"><![CDATA[http://www.microsoft.com]]> </Reference>
<Reference name="CVE" value="CVE"/>
</Root>
Like you can see I have a nested structure present in the data:
For starters I wrote define a RootDS which deals wid Root node and its related attributes. All ValueXPaths by default give me 1st Element in case of multiple element structures.
for eg: //Root/ExtendedLanguage/Match/@match-order gives me value 0. What I needed was some way to show all 3 values in the grid.
I created the following datasources:
Code:
public RootDS(String identifier) { setID(identifier); setDataFormat(DSDataFormat.XML); DataSourceTextField nameField = new DataSourceTextField("name", "Name"); nameField.setValueXPath("@name"); DataSourceTextField descField = new DataSourceTextField("description", "Description",500); descField.setValueXPath("Description"); DataSourceTextField protocolField = new DataSourceTextField("protocol", "Protocol"); protocolField.setValueXPath("@protocol"); DataSourceTextField eventGroupField = new DataSourceTextField("eventGroup", "Event Group"); eventGroupField.setValueXPath("EventGroup"); DataSourceTextField refNameField = new DataSourceTextField("refName", "Reference Type"); refNameField.setValueXPath("Reference/@name"); //This is for the ExtendedLanguage Element containing multiple match elements DataSourceField matchField = new DataSourceField("match",FieldType.TEXT, "Match"); matchField.setValueXPath("ExtendedLanguage/Match"); **matchField.setTypeAsDataSource(new RestDataSource()); matchField.setMultiple(true); // This part doesnt work and I cannot find any attribute named order in the response.getData(); DataSourceField matchOrder = new DataSourceField("order",FieldType.TEXT,"Order"); matchOrder.setTypeAsDataSource(new RestDataSource); matchOrder.setMultiple(true); matchOrder.setValueXPath("ExtendedLanguage/Match/@match-order");
matchField.setTypeasDataSource(ExtendedLanguageDS.getInstance());
This has no apparent difference since no matter what fields I put in this datasource they have no effect on the first one.
Code:
public class ExtendedLanguageDS extends RestDataSource { private static ExtendedLanguageDS instance = null; public static ExtendedLanguageDS getInstance() { if (instance == null) { instance = new ExtendedLanguageDS("extendedLangTypeDS"); } return instance; } public ExtendedLanguageDS(String identifier) { setID(identifier); setDataFormat(DSDataFormat.XML); // Doesnt matter whether u hv fields or not.. it still shows the objects... /*DataSourceField matchField = new DataSourceField("match",FieldType.TEXT,"Match"); matchField.setMultiple(true); matchField.setValueXPath("Root/ExtendedLanguage/Match"); DataSourceField matchOrder = new DataSourceField("order",FieldType.INTENUM,"Order"); matchOrder.setTypeAsDataSource(MatchDS.getInstance()); matchOrder.setMultiple(true); matchOrder.setValueXPath("Root/ExtendedLanguage/Match/@match-order"); setFields(matchField, matchOrder); */ } }
So what I concluded from this was when the Xpath //Root/ExtendedLanguage/Match is fired, I get the match elements as JS Objs from the server (which in my case is coming from eixstDB via restlets).
If on the matchField if I setTypeAsDataSource it allows me to say that it belongs to another datasource ==> its nested.
I have a few questions on this and let me tell you that I have not understood datasources completely.
1) Why are the fields in the second datasource absolutely redundant?
2) How shud I get the attribute values for eg: match-order or pattern coz it seems setChildTagName can only get values of Elements. for eg: I was able to get DUMMY1 and DUMMY2 to be displayed in the grid coz they are in the structure <EventGroup>value</EventGroup>
3) Incase of ExtendedLanguage where match Elements inturn consists of different elements like PCRE, ExtendedPattern, how should its Datasource be defined so that all the elements are recognized.
I would highly appreciate any help on this since I spent 4 days and really havent got through anything.
Thanks,
Hetal
Comment