Re: Iterate a Set of data

"Newman, John W" <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <721876F56F42304A8CB1CCFF9BFC09BB129385ED@MSXMBXNSPRD09.acct.upmchs.net>
private Set<Abc> riskSummaryRpt;
{ riskSummaryRpt.add("1"); riskSummaryRpt.add("2"); riskSummaryRpt.add("3");  }

[#list riskSummaryRpt as x]
   ${x}
[/#list]

2 3 1

That will show the values as they are ordered in the underlying collection (already different from what you need).  Sets are not ordered collections.  You may need to change your implementation from HashSet<T>() to LinkedHashSet<T>() which will preserve the order of the items as they are inserted.  You may also want to consider using a List<T> and ArrayList<T>() since your collection is ordered in real life - the only difference there would be you're losing the grouping and allowing duplicates which the set will do differently.

The freemarker code you posted is not doing any ordering.  It's just printing out blobs of text based on the ordering of the underlying collection (which is unordered).  As Daniel previously stated.  If you can't order the backend collection, you'll have to make your template a lot smarter to perform the ordering (probably doing string building or building a parallel index array and even two passes).



From: Geeth Lochana [mailto:[email protected]]
Sent: Sunday, September 25, 2011 12:00
To: [email protected]
Subject: Re: [FreeMarker-user] Iterate a Set of data

order mean , what i put in the out put. it's not like that afetr run it.
if the first record is totalVariance, and second record is factor in the collection.
the output like as below.
                     <totalVariance>
                             <risk>12.32</risk>
                     </totalVariance>
                    <factor>
                        <risk>12.32</risk>
                     </factor>
                     <specific>
                         <risk>12.32</risk>
                     </specific>

But i need the order of what i put in the template.


Best Regards,
Geeth,
Mobile : +94 77 355 0798

________________________________
From: Daniel Dekany [via FreeMarker] <[hidden email]</user/SendEmail.jtp?type=node&node=3841589&i=0>>
To: Geeth Lochana <[hidden email]</user/SendEmail.jtp?type=node&node=3841589&i=1>>
Sent: Saturday, September 24, 2011 1:02 PM
Subject: Re: Iterate a Set of data
What ordering are you expecting? The order of the riskSummaryRepors
will be the same as the Set gives them to FreeMarker.


Friday, September 23, 2011, 2:20:42 PM, Geeth Lochana wrote:

> I have collection of data, record as like follows.
> Class RiskSummaryRpt{
>     private String name;
>     private String value;
>  }
>
> Class Report{
>     private Set<Abc> riskSummaryRpt;
> }
>
> i want to get following out put using freemarker template
>
> using above collection i want to get single record.
>
> this is the current template i have
> <#list report.riskSummaryRpt as param>
>                 <#if param.name == 'Factor'>
>                     <factor>
>                         <risk>${param.riskVal!""}</risk>
>                     </factor>
>                 <#elseif param.name == 'Stock Specific'>
>                     <specific>
>                        <risk>${param.riskVal!""}</risk>
>                     </specific>
>                 <#elseif param.name == 'Total'>
>                     <totalVariance>
>                          <risk>${param.riskVal!""}</risk>
>                     </totalVariance>
>                 &lt;/#if&gt;
>         &lt;/#list&gt;
>
> i need to get following output with correct order of tags.
>                     <factor>
>                         <risk>12.32</risk>
>                     </factor>
>                     <specific>
>                         <risk>12.32</risk>
>                     </specific>
>                     <totalVariance>
>                         <risk>12.32</risk>
>                     </totalVariance>
>
>
> but i couldn't get the order is mismatch.
> Any one have any idea to over come this issue.
--
Best regards,
 Daniel Dekany


------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user

________________________________
If you reply to this email, your message will be added to the discussion below:
http://freemarker.624813.n4.nabble.com/Iterate-a-Set-of-data-tp3836641p3838859.html
To unsubscribe from Iterate a Set of data, click here.


________________________________
View this message in context: Re: Iterate a Set of data<http://freemarker.624813.n4.nabble.com/Iterate-a-Set-of-data-tp3836641p3841589.html>
Sent from the freemarker-user mailing list archive<http://freemarker.624813.n4.nabble.com/freemarker-user-f624814.html> at Nabble.com.

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2

_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.