Dynamic parameter for a java method defined in the jet file [message #9793] |
Sun, 01 April 2007 07:17 |
Eclipse User |
|
|
|
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 |
Paul Elder 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
>
>
>
>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.03067 seconds