Loop map with entity - spring

Have some for:
for(int i = 0; i < ids.size(); i++){
List<NomenclatureTypeFirst> nmtf = nomenclatureTypeFirstService.getAllByRequest(ids.get(i));
map.put(ids.get(i), nmtf);
}
Tried to uset th:text on value like this:
<table>
<tr th:each="entry, stats : ${map}">
<td th:text="${entry.key}"></td>
<td th:text="${entry.value.detname}"></td>
</tr>
</table>
But catch:
Property or field 'detname' cannot be found on object of type 'java.util.ArrayList' - maybe not public or not valid?
How can I do this?

The value of your map is a list, so you have to iterate over the values:
<table>
<tr th:each="entry, stats : ${map}">
<td th:text="${entry.key}"></td>
<table>
<tr th:each="value : ${entry.value}">
<td th:text="${value.detname}"></td>
</tr></table>
</tr>
</table>

Related

: EL1008E: Property or field 'LEVEL' cannot be found on object of type 'java.util.ArrayList' - maybe not public or not valid?

please assist with the below. I am trying to display an arraylist returned from the controller and display it to an Html table but I get the above error.
here is my controller code:
#GetMapping(value="/chart" )
public List<List<CanvasjsChartData.DataPointModel>> chart(Model modelMap) {
List<List<CanvasjsChartData.DataPointModel>> dataPointsList = canvasjsChartService.getCanvasjsChartData();
modelMap.addAttribute("dataPointsList", dataPointsList);
System.out.println("dataPointsList");
return dataPointsList;
}
and this is the table I want to display my list in
<table class="table" id="dataTable" style="width:100%">
<thead>
<th>Level</th>
<th>Occurences</th>
</thead>
<tbody>
<tr th:each="item :${dataPointsList}">
<td th:text="${item.LEVEL}"> </td>
<td th:text="${item.OCCURENCES}"> </td>
</tr>
</tr>
</tbody>
I know for sure the ArrayList has the data I require as shown below I dont know why its giving me the error
Your debug shows you have an List<List<CanvasjsChartData.DataPointModel>> (two Lists inside of each other) -- when your HTML is expecting List<CanvasjsChartData.DataPointModel>. You should fix that in your controller/model by only returning a single list.
You could also display your HTML like this (where you loop over the 0th element of the outer array):
<tr th:each="item :${dataPointsList[0]}">
<td th:text="${item.LEVEL}" />
<td th:text="${item.OCCURENCES}" />
</tr>

ColdFusion dataTable returning f is undefined

I'm adding dataTable to my coldFusion project, but it is returning: Uncaught TypeError: f is undefined
Code:
<table id="webPosttable" cellpadding="5" cellspacing="0">
<thead>
<tr>
<th>DATE</th>
<th>CK</th>
<th>NAME</th>
<th>IN</th>
<th>RATE</th>
<th>COST</th>
</tr>
</thead>
<tbody>
<cfoutput query="myQuery">
<cfset totalreportin = totalreportin + val(counter)>
<cfset totalreportcost = rate*counter + totalreportcost>
<tr>
<TD>#inserteddate#</TD>
<TD>#ck#</TD>
<TD>#fullname#</td>
<TD>#counter#</TD>
<td>#decimalformat(rate)#</td>
<td>#dollarformat(rate*counter)#</td>
</tr>
</cfoutput>
</tbody>
<tfoot>
<cfoutput>
<tr>
<TD colspan="3">TOTAL:</TD><td>#totalreportin#</td><TD></td><td>#dollarformat(totalreportcost)#</td>
<TD colspan="3">AVERAGE:</TD><td><Cfif incomingreport.recordcount GT 0>#decimalformat(val(totalreportin/incomingreport.recordcount))#<Cfelse>0</CFIF></td>
</tr>
<tr>
<td></td><td><Cfif totalreportin GT 0>#dollarformat(totalreportcost/totalreportin)#<cfelse>0</cfif></td>
</tr>
</cfoutput>
</tfoot>
</table>
<script>
$('#webPosttable').DataTable({
"lengthChange": false,
"paging": false,
"bInfo" : false,
"dom": '<"pull-left"f><"pull-right"l>tip'
});
</script>
Does anyone know what if something is missing in my table structure or javascript datable settings?
Thanks
The problem won't be in your Coldfusion code, it will be the structure of your <tfoot> content. The number of columns in the tfoot doesn't match the number of columns in the rest of your table. Even the two trs within your tfoot don't match each other.
Comment out the tfoot temporarily to test whether it works without, then balance up the columns and put it back in.
eg:
<tfoot>
<cfoutput>
<tr>
<TD>TOTAL:</TD>
<td>#totalreportin#</td>
<td></td>
<td>#dollarformat(totalreportcost)#</td>
<TD>AVERAGE:</TD>
<td><Cfif incomingreport.recordcount GT 0>#decimalformat(val(totalreportin/incomingreport.recordcount))#<Cfelse>0</CFIF></td>
</tr>
<tr>
<td colspan="5"></td>
<td><Cfif totalreportin GT 0>#dollarformat(totalreportcost/totalreportin)#<cfelse>0</cfif></td>
</tr>
</cfoutput>
</tfoot>
If you still have errors after that then I'd advise updating the question to include the code showing which version of jQuery+datatables you're including and where and how you're including it. You may also need to wrap your script in a $(document).ready( function () { ...

Html Agility Pack loop through Specific Row

I have a table like this
<table>
<thead>
<tr>
<th>Name</th>
<th>Department</th>
<th>Gender</th>
</tr>
</thead>
<tbody>
<tr id="data1">
</tr>
<tr>
</tr>
</tbody>
And I want to use Html Agility Pack to parse its specific row i.e i want to display row next to row which has id=data1
below is code I am trying ...
//Selecting Document Node....
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(data);
//Selecting Specific Node...
var tableNodes = doc.DocumentNode.SelectNodes("//table");
Your xpath should be like this:
//table/tbody/tr[#id='data1']/following-sibling::tr

Not able to apply slice to viewmodel knockout

I am unable to apply slice or substr to GId due to the following error message:
Uncaught TypeError: Unable to process binding "foreach: function (){return waititem }"
Message: Unable to process binding "style: function (){return { color:GId.slice(0,1) =='TR'?'black':'red'} }"
Message: undefined is not a function
Html
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
</tr>
</thead>
<tbody data-bind="foreach: waititem">
<tr data-bind="style: { color: GId.slice(0,1) == 'TR'? 'black' : 'red' }">
<td data-bind="text: PId"></td>
<td data-bind="text: PName"></td>
</tr>
</tbody>
</table>
How can I apply slice to check for the presence of a particular substring and style the row respectively?
You are using the slice method in your style binding wrongly. You need to use the syntax of slice as
slice(start, end)
where start has default of 0 for initial position and end will be the end character. In your scenario the slice will return a string of length 1 as you have used slice(0,1) but you are comparing with 'TR' which is of length 2. Instead of that you need to use slice(0, 2) === 'TR'.
<tr data-bind="style: { color: GId.slice(0,2) == 'TR'? 'black' : 'red' }">
<td data-bind="text: PId"></td>
<td data-bind="text: PName"></td>
</tr>
DEMO

How can I create a dynamic image source with MVC3 and Razor?

I have a view that attempts to build a table off of the passed in Model. I'd like to generate an image with a source that is changed based on the iteration of a loop but can't seem to get it to work. I can do this in JQuery but I would like to do it with razor. I have the following table body:
<tbody>
#{for (var ix = 0; ix <= Model.Value.Count - 1; ix++)
{
<tr>
<td style="width: 10%"><img src="http://gmap.com/marker" + #ix + 1 + ".png" /></td>
<td style="width: 75%">#Model("fullname")</td>
</tr>
}
<tbody>
That first TD is the problem area. I attempted it but... Thanks for the help.
Since it is razor you do not need to add the rendered output to your url. Try this:
#{for (var ix = 0; ix <= Model.Value.Count - 1; ix++)
{
<tr>
<td style="width: 10%"><img src="http://gmap.com/marker#(ix + 1).png" /></td>
<td style="width: 75%">#Model("fullname")</td>
</tr>
}
I haven't tested it but I believe it will fix your issue.

Resources