Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Dynamic parameter for a java method defined in the jet file
Dynamic parameter for a java method defined in the jet file [message #9793] Sun, 01 April 2007 07:17 Go to next message
Eclipse UserFriend
Originally posted by: thomas.pellegrin.gmail.com

Good morning,

I need some help for JET. I would like to use a method defined in my jet
file and use dynamic parameter when I call it. how can I do that? is it
possible?

eg:
<%!

public String getType(String t) {

if (t.compareTo("s")==0){
return "String";
}
return "To define";
}
%>

<%= getType( [Dynamic value] ) %>
something like that
<%= getType(<c:get select="$p/@type" />)%> is it possible? or how can I do
something like that?

Thanks in advance,
Thomas
Re: Dynamic parameter for a java method defined in the jet file [message #9976 is a reply to message #9793] Wed, 04 April 2007 12:55 Go to previous message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Thomas

No,

<%= getType(<c:get select="$p/@type" />)%>

is not valid syntax.

However, the JET context and XPath engine are available to you in Java code.

I'd recommend a class like the following:

import org.eclipse.jet.XPathContextExtender;

public class DoXPath {
public static String get(JET2Context context, String xpath) {
XPathContextExtender xpe =
XPathContextExtender.getInstance(context);
return xpe.resolveAsString(xpe.currentXPathContextObject(), xpath);
}
}

Depending on where you place DoXPath, you may have to add a
<%@jet imports="....DoXPath" %>

to your template.

Then, your Java expression becomes:

<%= getType(DoXPath.get(context, "$p/@type")) %>

Paul

"Thomas" <thomas.pellegrin@gmail.com> wrote in message
news:euqaln$hje$1@build.eclipse.org...
> Good morning,
>
> I need some help for JET. I would like to use a method defined in my jet
> file and use dynamic parameter when I call it. how can I do that? is it
> possible?
>
> eg:
> <%!
>
> public String getType(String t) {
>
> if (t.compareTo("s")==0){
> return "String";
> }
> return "To define";
> }
> %>
>
> <%= getType( [Dynamic value] ) %>
> something like that
> <%= getType(<c:get select="$p/@type" />)%> is it possible? or how can I do
> something like that?
>
> Thanks in advance,
> Thomas
>
>
>
>
>
>
Previous Topic:How to get setVariable value back
Next Topic:JET2 - invoking with a different input file.
Goto Forum:
  


Current Time: Tue Apr 16 07:43:21 GMT 2024

Powered by FUDForum. Page generated in 0.69627 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top