You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Verma, Abhishek (Abhishek V)" <ab...@hp.com> on 2006/12/05 08:45:15 UTC
Retreive values from a Structure.
Hi all,
I am a new to velocity.
I have a data structure in java like follow:-
--Section 1
------SubSection1.1
-----------Article 1
-----------Article 2
-----------Article 3
------SubSection1.2
-----------Article 4
-----------Article 5
-----------Article 6
--Section 2
------SubSection2.1
-----------Article 7
-----------Article 8
-----------Article 9
------SubSection2.2
-----------Article 10
-----------Article11
-----------Article 12
------SubSection2.3
-----------Article 13
-----------Article14
-----------Article 15
--Section 3
------SubSection3.1
-----------Article 16
------SubSection3.2
-----------Article 17
-----------Article18
-----------Article 19
------SubSection3.3
-----------Article 20
Now in the VTL i have to retreive these articles like the same structure
Any help is appreciated
==Abhishek==
Hewlett-Packard
Re: Retreive values from a Structure.
Posted by ap...@recks.org.
Hi,
since we can't guest hour your Java data structure looks like,
I will assume something like:
public class Report
{
public List<Section> getSections();
}
public class Section
{
public List<Subsection> getSubsections();
}
public class Subsection
{
public List<String> getArticles();
}
In the java code (e.g. VelocityViewServlet subclass):
context.put("report", myReportInstance);
In the velocity template:
#foreach( $section in $report.sections )
$section.title
#**##foreach( $subsection in $section.subsections )
$subsection.title
#* *##foreach( $article in $subsection.articles )
$article#*this uses the method toString() of the java class behind the article*#
#* *##end
#**##end
#end
If you need help on indenting or whitespace handling
just ask this list...
Cheers,
Christoph
P.S. Just before sending this, I saw that Claude already posted a
similar answer...
Verma, Abhishek (Abhishek V) wrote:
> Hi all,
> I am a new to velocity.
>
> I have a data structure in java like follow:-
>
> --Section 1
> ------SubSection1.1
> -----------Article 1
> -----------Article 2
> -----------Article 3
> ------SubSection1.2
> -----------Article 4
> -----------Article 5
> -----------Article 6
>
> --Section 2
> ------SubSection2.1
> -----------Article 7
> -----------Article 8
> -----------Article 9
> ------SubSection2.2
> -----------Article 10
> -----------Article11
> -----------Article 12
> ------SubSection2.3
> -----------Article 13
> -----------Article14
> -----------Article 15
>
> --Section 3
> ------SubSection3.1
> -----------Article 16
> ------SubSection3.2
> -----------Article 17
> -----------Article18
> -----------Article 19
> ------SubSection3.3
> -----------Article 20
>
>
> Now in the VTL i have to retreive these articles like the same structure
> Any help is appreciated
>
> ==Abhishek==
> Hewlett-Packard
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: Retreive values from a Structure.
Posted by Claude Brisson <cl...@renegat.net>.
What types of structures are you using on the java side? Arrays? Lists?
Custom objects ?
What do you want to display in VTL?
Let's say you put the articles in a list of lists of articles named
$articles in the context. IT would give something like:
#set($nb = 1)
#foreach($section in $articles)
--Section $velocityCount
#set($sec = $velocityCount)
#foreach($sub in $secion)
------SubSection ${sec}.$velocityCount
#foreach($art in $sub)
--------Article $nb
#set($nb = $nb + 1)
#end
#end
#end
Claude
Le mardi 05 décembre 2006 à 13:15 +0530, Verma, Abhishek (Abhishek V) a
écrit :
> Hi all,
> I am a new to velocity.
>
> I have a data structure in java like follow:-
>
> --Section 1
> ------SubSection1.1
> -----------Article 1
> -----------Article 2
> -----------Article 3
> ------SubSection1.2
> -----------Article 4
> -----------Article 5
> -----------Article 6
>
> --Section 2
> ------SubSection2.1
> -----------Article 7
> -----------Article 8
> -----------Article 9
> ------SubSection2.2
> -----------Article 10
> -----------Article11
> -----------Article 12
> ------SubSection2.3
> -----------Article 13
> -----------Article14
> -----------Article 15
>
> --Section 3
> ------SubSection3.1
> -----------Article 16
> ------SubSection3.2
> -----------Article 17
> -----------Article18
> -----------Article 19
> ------SubSection3.3
> -----------Article 20
>
>
> Now in the VTL i have to retreive these articles like the same structure
> Any help is appreciated
>
> ==Abhishek==
> Hewlett-Packard
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org