I have a jquery datable that should get loaded with a table data. I am using struts2 Hibernate.
JSP Page:
<script>
$(document).ready(function() {
$(".jqueryDataTable").dataTable({
"sPaginationType" : "full_numbers",
"bProcessing" : false,
"bServerSide" : false,
"sAjaxSource" : "getProductPropData",
"bJQueryUI" : true,
"aoColumns" : [
{ "mData": "densityId" },
{ "mData": "densityDescription" }
]
} );
} );
</script>
struts.xml
<package name="json" namespace="/" extends="json-default">
<action name="getProductPropData" class="com.test.action.PropertyListDataAction">
<result type="json">
<param name="excludeNullProperties">true</param>
<param name="noCache">true</param>
</result>
</action>
</package>
Action Class:
public String execute() throws Exception {
// TODO Auto-generated method stub
SessionFactory sf = (SessionFactory) ctx.getAttribute("SessionFactory");
ProductPropertyDAO pdao = new ProductPropertyDAOImpl(sf);
List<DensityGroup> dg = pdao.getProductPropListData("Density");
Gson gson = new Gson();
jsonData = gson.toJson(dg);
System.out.println("dg:"+dg);
return "success";
}
I am getting response from the database in json format but my datatable is not getting populated.
]2
JSON output:
{"jsonData":"[{\"densityId\":15,\"validationAware\":{}},{\"densityId\":11,\"densityDescription\":\"Mcvr\",\"validationAware\":{}},{\"densityId\":14,\"densityDescription\":\"test\",\"validationAware\":{}},{\"densityId\":16,\"densityDescription\":\"Chitti\",\"validationAware\":{}},{\"densityId\":12,\"densityDescription\":\"MCVR\",\"validationAware\":{}},{\"densityId\":13,\"densityDescription\":\"4\\\" DIA\",\"validationAware\":{}},{\"densityId\":14,\"densityDescription\":\"test\",\"validationAware\":{}},{\"densityId\":15,\"validationAware\":{}},{\"densityId\":21,\"densityDescription\":\"1 1\/4\\\" DIA\",\"validationAware\":{}},{\"densityId\":22,\"densityDescription\":\"3\/4\\\" DIA\",\"validationAware\":{}},{\"densityId\":37,\"densityDescription\":\"25\\\"DIA\",\"validationAware\":{}},{\"densityId\":24,\"densityDescription\":\"8\\\" DIA\",\"validationAware\":{}},{\"densityId\":25,\"densityDescription\":\"1 1\/8\\\" DIA\",\"validationAware\":{}},{\"densityId\":28,\"densityDescription\":\"6\\\"\",\"validationAware\":{}},{\"densityId\":29,\"densityDescription\":\"1\/2\\\" DIA\",\"validationAware\":{}},{\"densityId\":30,\"densityDescription\":\"EXHAUST STEAM\",\"validationAware\":{}},{\"densityId\":19,\"densityDescription\":\"1 1\/2\\\" DIA\",\"validationAware\":{}},{\"densityId\":44,\"densityDescription\":\"EXHAUSTCLADDING\",\"validationAware\":{}},{\"densityId\":1,\"densityDescription\":\"16 KG\",\"validationAware\":{}},{\"densityId\":11,\"densityDescription\":\"Mcvr\",\"validationAware\":{}},{\"densityId\":2,\"densityDescription\":\"20 KG\",\"validationAware\":{}},{\"densityId\":3,\"densityDescription\":\"24 KG\",\"validationAware\":{}},{\"densityId\":5,\"densityDescription\":\"48 KG\",\"validationAware\":{}},{\"densityId\":6,\"densityDescription\":\"64 KG\",\"validationAware\":{}},{\"densityId\":7,\"densityDescription\":\"96 KG\",\"validationAware\":{}},{\"densityId\":8,\"densityDescription\":\"100 KG\",\"validationAware\":{}},{\"densityId\":9,\"densityDescription\":\"128 KG \",\"validationAware\":{}},{\"densityId\":10,\"densityDescription\":\"120 KG \",\"validationAware\":{}},{\"densityId\":18,\"densityDescription\":\"144KG\",\"validationAware\":{}},{\"densityId\":23,\"densityDescription\":\"5\\\" DIA\",\"validationAware\":{}},{\"densityId\":26,\"densityDescription\":\"4\\\"\",\"validationAware\":{}},{\"densityId\":27,\"densityDescription\":\"125 KG\",\"validationAware\":{}},{\"densityId\":34,\"densityDescription\":\"10\\\" DIA\",\"validationAware\":{}},{\"densityId\":32,\"densityDescription\":\"18\\\" \",\"validationAware\":{}},{\"densityId\":33,\"densityDescription\":\"12\\\" DIA\",\"validationAware\":{}},{\"densityId\":35,\"densityDescription\":\"14\\\" DIA\",\"validationAware\":{}},{\"densityId\":36,\"densityDescription\":\"5\/8\\\" DIA\",\"validationAware\":{}},{\"densityId\":38,\"densityDescription\":\"(1\/2 x 24 SWG)\",\"validationAware\":{}},{\"densityId\":39,\"densityDescription\":\"8\\\" FLANGE\",\"validationAware\":{}},{\"densityId\":40,\"densityDescription\":\"6\\\" FLANGE\",\"validationAware\":{}},{\"densityId\":41,\"densityDescription\":\"3\\\" FLANGE\",\"validationAware\":{}},{\"densityId\":42,\"densityDescription\":\"25 MM DIA\",\"validationAware\":{}},{\"densityId\":43,\"densityDescription\":\"150 KG\",\"validationAware\":{}},{\"densityId\":46,\"densityDescription\":\"INSULATION WORK\",\"validationAware\":{}},{\"densityId\":47,\"densityDescription\":\"18\\\" DIA\",\"validationAware\":{}},{\"densityId\":16,\"densityDescription\":\"Chitti\",\"validationAware\":{}},{\"densityId\":45,\"densityDescription\":\"1 3\/8 DIA\",\"validationAware\":{}},{\"densityId\":56,\"densityDescription\":\"18 KG\",\"validationAware\":{}},{\"densityId\":55,\"densityDescription\":\"40 KG\",\"validationAware\":{}},{\"densityId\":48,\"densityDescription\":\"85 KG\",\"validationAware\":{}},{\"densityId\":49,\"densityDescription\":\"2\\\"\",\"validationAware\":{}},{\"densityId\":50,\"densityDescription\":\"12 KG\",\"validationAware\":{}},{\"densityId\":53,\"densityDescription\":\"FLANGES\",\"validationAware\":{}},{\"densityId\":51,\"densityDescription\":\"2 1\/2\\\" DIA\",\"validationAware\":{}},{\"densityId\":52,\"densityDescription\":\"INSULATION \",\"validationAware\":{}},{\"densityId\":54,\"densityDescription\":\"VALVES\",\"validationAware\":{}},{\"densityId\":57,\"densityDescription\":\"CLASS O\",\"validationAware\":{}},{\"densityId\":58,\"densityDescription\":\"140 KG\",\"validationAware\":{}},{\"densityId\":59,\"densityDescription\":\"30 KG\",\"validationAware\":{}}]"}
By default datatables looks for the 'data' element in the json.
It can't find it, therefore it's 'undefined'. DataTables provides a way to specify the element to use. Comparing your json with that on the documentation link below you should be able to specify ajax.dataSrc = "jsonData" or change "jsonData" to "data" in your data object.
I would recommend switching to the new naming convention for the datatable options if possible, it's more clear and the documentation is tailored towards it. If you can't use the new naming scheme changing your json object is probably the best option.
Documentation:
https://datatables.net/examples/ajax/custom_data_property.html
In my scenario, i have a new entity called "new_relations" with 2 fields (account1 and account2) that are both lookups to accounts.
In my accounts form i want to display a grid containing any record with the current account, in any of the 2 lookups, that exists in "new_relations" entity.
I´ve created account A and account B; created 1 record in new_relations with new_relations.account1 = account A and new_relations.account2 = account B.
So, when i open account A or Account B i want to see the record created in new_relations.
I have the following code, unfortunately its only showing the record in Account´s A form in my subgrid...
Can anyone help?
function FilterRelacao(){
var relacoes = document.getElementById("Relacoes");
var account = Xrm.Page.data.entity.getId();
var accountname = Xrm.Page.data.entity.attributes.get("name").getValue();
if(relacoes==null){
setTimeout(function () { FilterRelacao(); }, 2000);
return;
}
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='new_relations'>" +
"<attribute name='new_type' />" +
"<attribute name='new_accountid1' />" +
"<attribute name='new_accountid2' />" +
"<attribute name='new_relationsid' />" +
"<order attribute='new_accountid1' descending='true' />" +
"<filter type='and'>" +
"<condition attribute='statecode' operator='eq' value='0' />" +
"<filter type='or'>" +
"<condition attribute='new_accountid1' operator='eq' uitype='account' uiname='" + accountname+ "' value='" + account + "' />" +
"<condition attribute='new_accountid2' operator='eq' uitype='account' uiname='" + accountname + "' value='" + account + "' />" +
"</filter></filter>" +
"</entity>" +
"</fetch>";
relacoes.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid
relacoes.control.SetParameter("effectiveFetchXml", fetchXml); //set the fetch xml to the sub grid
relacoes.control.Refresh(); //refresh the sub grid using the new fetch xml
}
Your fetch XML looks correct to me. When you set up the subgrid did you set "Records" = "All Record Types" in the Data Source section? If you did not then the subgrid will append a condition to your fetchxml so that it returns only records related to the specific relationship that you specified.
Iam doing XML reading using dom concepts, But i couldn't retrieve values correctly.
I want to RETRIEVE BELOW PART using for loop statement
<area id="508" Type="paragraph" visible="1" source_ap="True" invert="False" rotation="0" ignoretext="0">
<pagename><![CDATA[11187_2014_06_14_000002_0004_NFHEZ]]></pagename>
<pagenumber>1</pagenumber>
<left>603</left>
<top>868</top>
<right>764</right>
<bottom>1132</bottom>
<polygon ispolygon="0" noofpoints="0"><![CDATA[]]></polygon>
</area>
HERE IS THE FULL SAMPLE XML WHERE I WANT TO RETRIEVE USING FOR LOOP.
<?xml version="1.0" encoding="UTF-8"?>
<articles>
<template istemplate="true" twidth="0" theight="0" uwidth="0" uheight="0" ubottom="0"> </template>
<article name="11187_2014_06_14_000002_0004_NFHEZ_00004" id="4">
<articlename><![CDATA[11187_2014_06_14_000002_0004_NFHEZ_00004]]></articlename>
<input_pages>
<page name="11187_2014_06_14_000002_0004_NFHEZ" number="3">
<pagepdfheight>1125</pagepdfheight>
<pagepdfwidth>786</pagepdfwidth>
<pagejpgheight>1125</pagejpgheight>
<pagejpgwidth>786</pagejpgwidth>
<pagejpgresolution>72</pagejpgresolution>
<name><![CDATA[11187_2014_06_14_000002_0004_NFHEZ]]></name>
<Article_Area>0</Article_Area>
<Article_percentage>0</Article_percentage>
</page>
</input_pages>
<NoOfPage>1</NoOfPage>
<output_pages>
<page number="1" height="0" width="0"/>
</output_pages>
<read>
<area id="508" Type="paragraph" visible="1" source_ap="True" invert="False" rotation="0" ignoretext="0">
<pagename><![CDATA[11187_2014_06_14_000002_0004_NFHEZ]]></pagename>
<pagenumber>1</pagenumber>
<left>603</left>
<top>868</top>
<right>764</right>
<bottom>1132</bottom>
<polygon ispolygon="0" noofpoints="0"><![CDATA[]]></polygon>
</area>
<area id="507" Type="paragraph" visible="1" source_ap="True" invert="False" rotation="0" ignoretext="0">
<pagename><![CDATA[11187_2014_06_14_000002_0004_NFHEZ]]></pagename>
<pagenumber>1</pagenumber>
<left>462</left>
<top>868</top>
<right>601</right>
<bottom>1131</bottom>
<polygon ispolygon="0" noofpoints="0"><![CDATA[]]></polygon>
</area>
</read>
My code is:
Dim doc As New XmlDocument()
Dim sValue, sPgName As String
Dim sLeft, sTops, sRight, sBottom As String
Dim ObjZoneInfo As CZoneInfo
Try
doc.Load(sFile)
If doc.ChildNodes.Item(0).Name = "xml" Then
If doc.ChildNodes.Item(1).Name = "articles" Then
For i As Integer = 0 To doc.ChildNodes.Item(1).ChildNodes.Count - 1
If doc.ChildNodes.Item(2).ChildNodes.Item(i).Name = "article" Then
ObjZoneInfo = New CZoneInfo
For j As Integer = 0 To doc.ChildNodes.Item(2).ChildNodes.Item(i).ChildNodes.Count - 1
sValue = doc.ChildNodes.Item(1).ChildNodes.Item(i).ChildNodes.Item(j).InnerText
If doc.ChildNodes.Item(1).ChildNodes.Item(i).ChildNodes.Item(j).Name = "page_name" Then
If sProFiles.Contains(sValue) = False Then
sProFiles.Add(sValue)
End If
ObjZoneInfo.PageName = sValue : sPgName = sValue
I understand you are searching only for nodes with "area" tag, so try this:
Dim tagAreas as XmlNodeList = doc.GetElementsByTagName("area")
You can then use a For Each loop:
For Each tagArea as XmlElement in tagAreas Then
'______your code here. If you wanted to retrieve the "area" tag I don't understand the code you posted
Next
Now, to access attributes of the area nodes, you must use the following:
Dim area_id as Integer = Integer.parse(tagArea.GetAttribute("id")) 'if you want to obtain id data as integer
Dim area_type as String = tagArea.GetAttribute("type")
'so etc___________________
if you want to access the child nodes:
Dim area_pagenum as Integer = Integer.parse(tagArea("pagenumber"))
I am creating an XDocument with the following structure:
Dim xDocHandle As XDocument =
New XDocument(
New XDeclaration("1.0", Nothing, Nothing),
New XElement("Element",
New XElement("Dialogue",
New XElement("Desc", AppDesc),
New XElement("Num", Num),
New XElement("Ref", Ref),
New XElement("ms", Ms),
New XElement("im", Im))
))
To have the following output:
<Element>
<Dialogue>
<Desc>test</Desc>
<Num>1</Num>
<Ref></Ref>
<ms>2411616</ms>
<im></im>
</Dialogue>
</Element>
I want to add the following headers
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns="">
Should I add them as new XDeclaration , new XElement?
Whats the type of the soap headers?
Any help would be appreciated.
<soap:Envelope> and <soap:Body> are clearly elements. You can do something like this to construct XML with soap header :
'create <Element> node :'
Dim element As XElement = New XElement("Element",
New XElement("Dialogue",
New XElement("Desc", AppDesc),
New XElement("Num", Num),
New XElement("Ref", Ref),
New XElement("ms", Ms),
New XElement("im", Im))
)
'create <soap:Envelope> node and add <Element> as child of <soap:Body> :'
Dim soap As XNamespace = "http://www.w3.org/2001/12/soap-envelope"
Dim soapEnvelope As XElement = New XElement(soap + "Envelope",
New XAttribute(XNamespace.Xmlns + "soap", soap.NamespaceName),
New XAttribute(soap + "encodingStyle", "http://www.w3.org/2001/12/soap-encoding"),
New XElement(soap + "Body", element))
'create XDocument and set <soap:Envelope> as content'
Dim xDocHandle As XDocument =
New XDocument(
New XDeclaration("1.0", Nothing, Nothing),
soapEnvelope
)
Output :
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body>
<Element>
<Dialogue>
<Desc>test</Desc>
<Num>1</Num>
<Ref></Ref>
<ms>2411616</ms>
<im></im>
</Dialogue>
</Element>
</soap:Body>
</soap:Envelope>
I'm building an XML file dynamically using new XElement(), and midway through the file creation I need to iterate over a set of child records and create XElements for them. The problem I'm having is that I need to create more than 1 XElement per iteration. This is a my loop:
from t in trans.SalesTransactionLines
select new XElement("text", new XAttribute("lang", "en"), t.ItemName)
This works fine, but I need an additional 'position' XElement before each 'text' Element. This is the kind of thing I want, which doesn't work:
from t in trans.SalesTransactionLines
select new XElement("position",new XAttribute("x", "40"), new XAttribute("y", "420")),
new XElement("text", new XAttribute("lang", "en"), t.ItemName)
This is the result I'm looking for:
<position x="40" y="420" />
<text>Fender Classic Strat 70s Natural RN</text>
<position x="40" y="420" />
<text>Fender Classic 50s Tele White Blonde</text>
Use method based syntax and SelectMany method instead:
trans.SalesTransactionLines.SelectMany(x => new[] {
new XElement("position",
new XAttribute("x", "40"),
new XAttribute("y", 420")),
new XElement("text",
new XAttribute("lang", "en"),
x.ItemName)
})