[JET2] double c:iterate [message #34638] |
Mon, 01 October 2007 16:23 |
Eclipse User |
|
|
|
Originally posted by: felouerkhaoui.gmail.com
I have a double c:iterate like this.
<c:iterate select="/Domaine/subDomaines" var="subDomaine">
<java:package name="{/Domaine/@rootPackage}/{$subDomaine/@name}">
<c:iterate select="/Domaine/subDomaines/dataLayer/entites"
var="entite">
<java:class name="{$entite/@name}"
template="templates/dataLayer/entite.jet"/>
</c:iterate>
</java:package>
</c:iterate>
The issue I have is that I can't get the package name inside the second
script entite.jet.
I tried to give it the same path as used ti create the package
({/Domaine/@rootPackage}/{$subDomaine/@name}), it gave me an execution
error.
Thanks in advance.
|
|
|
Re: [JET2] double c:iterate [message #34707 is a reply to message #34638] |
Tue, 02 October 2007 13:18 |
Paul Elder Messages: 849 Registered: July 2009 |
Senior Member |
|
|
Fatima:
First, I'm guessing you really want:
<c:iterate select="/Domaine/subDomaines" var="subDomaine">
<java:package name="{/Domaine/@rootPackage}/{$subDomaine/@name}">
<%--
I presume you want to iterate over only the entities in the current
subdomain, not all entities in all subdomains...
--%>
<c:iterate select="$subDomaine/dataLayer/entites" var="entite">
<java:class name="{$entite/@name}"
template="templates/dataLayer/entite.jet"/>
</c:iterate>
</java:package>
</c:iterate>
As for getting the package name, there is no predefined variable for doing
this. However, JET does have general mechanism for calculating and storing
values that can then be used in templates. It is the <c:set> tag, which will
set or create an attribute on any element in your input model. JET calls
these 'derived attributes'. A derived attribute DOES NOT have to be declared
in the input domain/schema. Derived attribute values do not affect your
original model, they are only stored until the JET transformation completes.
The typical architecture of a main.jet would be:
<%-- iterate of over the model, doing c:set's --%>
<%-- iterate over the model, doing ws:file, java:... actions --%>
So, I'd redo you code as follows:
<%-- Calculate values needed for template expansion --%>
<c:iterate select="/Domaine/subDomaines" var="subDomaine">
<%-- Define $subDomaine/@package to be the current package --%>
<c:set select="$subDomaine" name="package"><c:get
select="/Domaine/@rootPackage"/>.<c:get select="$subDomain/@name"/></c:set>
<c:iterate select="$subDomaine/dataLayer/entites" var="entite">
<%-- do what ever c:set's or necessary for entities -->
</c:iterate>
</c:iterate>
<%-- Expand templates, and save their results... --%>
<c:iterate select="/Domaine/subDomaines" var="subDomaine">
<java:package name="{$subDomain/@package}">
<c:iterate select="$subDomaine/dataLayer/entites" var="entite">
<%-- in entite.jet, $subDomain/@package is the package, and
$entite/@name is the class name --%>
<java:class name="{$entite/@name}"
template="templates/dataLayer/entite.jet"/>
</c:iterate>
</java:package>
</c:iterate>
The general philosophy is to prefer the creation of derived attributes to
doing calculation in JET templates. This way, templates are less cluttered.
Paul
"Fatima Zohra" <felouerkhaoui@gmail.com> wrote in message
news:988a903697ffbd9db647705ee722c43f$1@www.eclipse.org...
>I have a double c:iterate like this.
>
> <c:iterate select="/Domaine/subDomaines" var="subDomaine">
> <java:package name="{/Domaine/@rootPackage}/{$subDomaine/@name}">
> <c:iterate select="/Domaine/subDomaines/dataLayer/entites" var="entite">
> <java:class name="{$entite/@name}"
> template="templates/dataLayer/entite.jet"/>
> </c:iterate>
> </java:package>
> </c:iterate>
>
> The issue I have is that I can't get the package name inside the second
> script entite.jet.
>
> I tried to give it the same path as used ti create the package
> ({/Domaine/@rootPackage}/{$subDomaine/@name}), it gave me an execution
> error.
>
> Thanks in advance.
>
|
|
|
Powered by
FUDForum. Page generated in 0.02962 seconds