Javascript - TemplateSequenceModel

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Javascript - TemplateSequenceModel

Edwin S. Ramirez
Hello *,

I use FreeMarker with Rhino to present database information.  For most
queries it is fine to extract all the database records into an array and
then use that in the template.  For some queries which return a very
large data set, I would like to let the template engine retrieve the
records from the database.

I have a Javascript object which implements a "next" method (returns the
next record as a hash) and a rows method (returns the record count).

I know that I can create a template which uses these functions directly,
but I would like to use the same template for arrays as well.

In theory, I should be able to use JavaAdapter to create a
TemplateSequenceModel implementation directly in Javascript.  But, I am
running into problems.

Does anybody have any experiences with something like this?

Thanks,
-Edwin S. Ramirez-


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: Javascript - TemplateSequenceModel

Attila Szegedi-3
No specific experience, but I understand what you're saying. What's  
the problem you're running into? Also, what Rhino version are you using?

Attila.

On 2008.04.11., at 21:22, Edwin S. Ramirez wrote:

> Hello *,
>
> I use FreeMarker with Rhino to present database information.  For most
> queries it is fine to extract all the database records into an array  
> and
> then use that in the template.  For some queries which return a very
> large data set, I would like to let the template engine retrieve the
> records from the database.
>
> I have a Javascript object which implements a "next" method (returns  
> the
> next record as a hash) and a rows method (returns the record count).
>
> I know that I can create a template which uses these functions  
> directly,
> but I would like to use the same template for arrays as well.
>
> In theory, I should be able to use JavaAdapter to create a
> TemplateSequenceModel implementation directly in Javascript.  But, I  
> am
> running into problems.
>
> Does anybody have any experiences with something like this?
>
> Thanks,
> -Edwin S. Ramirez-




-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: Javascript - TemplateSequenceModel

Edwin S. Ramirez
Thank you for taking a look, I appreciate any advice that you can give
me.  The code is below, followed by the stack trace which shows a couple
of debug statements from JavaScript on the JavaScript object which
implements the "TemplateSequenceModel" interface.  I am using Rhino 1.7R1.

JAVASCRIPT:

function sequence(fdat) {
     var obj = {};

     obj.get = function(idx) {
         return Packages.TemplateSequence.Model({f: "Rec# " + idx});
     }

     obj.size = function() {
         return 5;
     }

     fdat.data = new JavaAdapter(Packages.TemplateSequence, obj);

     debug(fdat.data.size());
     debug(fdat.data.get(3));


     writeln(getTemplate({tplname: "/Test/sequence.tpl", data: fdat}));
}

TEMPLATE:

[#list data as d]
${d.f}<br/>
[/#list]

JAVA:

import freemarker.template.*;
import freemarker.ext.rhino.*;

public class TemplateSequence implements TemplateSequenceModel {
     static RhinoWrapper bw = new RhinoWrapper();

     public TemplateSequence() {}

     public TemplateModel get(int idx) {
         System.out.println("In Get!");
         return null;
     }

     public int size() { return 0; }

     public static TemplateModel Model(Object sc) {
         System.out.println("In Model!");
         try {
             return bw.wrap(sc);
         } catch(Exception e) {
             e.printStackTrace();
         }
         return null;
     }
}

STACK TRACE:
5
In Model!
freemarker.ext.rhino.RhinoScriptableModel@5fa80aea
org.mozilla.javascript.EvaluatorException: Java class "adapter1" has no
public instance field or method named "0". (lib/init.js#149)
         at
org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:109)
         at
org.mozilla.javascript.Context.reportRuntimeError(Context.java:922)
         at
org.mozilla.javascript.Context.reportRuntimeError(Context.java:978)
         at
org.mozilla.javascript.Context.reportRuntimeError2(Context.java:948)
         at
org.mozilla.javascript.JavaMembers.reportMemberNotFound(JavaMembers.java:873)
         at
org.mozilla.javascript.NativeJavaObject.get(NativeJavaObject.java:117)
         at
org.mozilla.javascript.ScriptableObject.getProperty(ScriptableObject.java:1603)
         at
freemarker.ext.rhino.RhinoScriptableModel.get(RhinoScriptableModel.java:55)
         at freemarker.core.LoopContext.runLoop(LoopContext.java:109)
         at freemarker.core.Environment.process(Environment.java:376)
         at freemarker.core.ast.IteratorBlock.execute(IteratorBlock.java:97)
         at freemarker.core.Environment.render(Environment.java:219)
         at freemarker.core.Environment.process(Environment.java:194)
         at freemarker.template.Template.process(Template.java:242)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:160)
         at
org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:243)
         at
org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:76)
         at org.mozilla.javascript.gen.c1._c23(lib/init.js:149)
         at org.mozilla.javascript.gen.c1.call(lib/init.js)
         at
org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:97)
         at org.mozilla.javascript.gen.c26._c1(<events/test.js>:23)
         at org.mozilla.javascript.gen.c26.call(<events/test.js>)
         at
org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:97)
         at org.mozilla.javascript.gen.c29._c0(test:1)
         at org.mozilla.javascript.gen.c29.call(test)
         at
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:401)
         at
org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3003)
         at org.mozilla.javascript.gen.c29.call(test)
         at org.mozilla.javascript.gen.c29.exec(test)
         at org.mozilla.javascript.Context.evaluateString(Context.java:1088)
         at idcServer.catalyst.service(catalyst.java:66)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:45)
         at
winstone.ServletConfiguration.execute(ServletConfiguration.java:249)
         at winstone.RequestDispatcher.forward(RequestDispatcher.java:335)
         at
winstone.RequestHandlerThread.processRequest(RequestHandlerThread.java:244)
         at winstone.RequestHandlerThread.run(RequestHandlerThread.java:150)
         at java.lang.Thread.run(Thread.java:595)


Attila Szegedi wrote:

> No specific experience, but I understand what you're saying. What's  
> the problem you're running into? Also, what Rhino version are you using?
>
> Attila.
>
> On 2008.04.11., at 21:22, Edwin S. Ramirez wrote:
>> Hello *,
>>
>> I use FreeMarker with Rhino to present database information.  For most
>> queries it is fine to extract all the database records into an array  
>> and
>> then use that in the template.  For some queries which return a very
>> large data set, I would like to let the template engine retrieve the
>> records from the database.
>>
>> I have a Javascript object which implements a "next" method (returns  
>> the
>> next record as a hash) and a rows method (returns the record count).
>>
>> I know that I can create a template which uses these functions  
>> directly,
>> but I would like to use the same template for arrays as well.
>>
>> In theory, I should be able to use JavaAdapter to create a
>> TemplateSequenceModel implementation directly in Javascript.  But, I  
>> am
>> running into problems.
>>
>> Does anybody have any experiences with something like this?
>>
>> Thanks,
>> -Edwin S. Ramirez-
>
>
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> Don't miss this year's exciting event. There's still time to save $100.
> Use priority code J8TL2D2.
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: Javascript - TemplateSequenceModel

Attila Szegedi-3
Hi,

I've looked into it, and it's an interesting case. What happens here  
is that Rhino generates a wrapper class that extends TemplateSequence  
(which implements TemplateSequenceModel), and creates an instance of  
it, but that's then further wrapped into a Rhino "NativeJavaObject",  
which is a wrapper for a Java class. Our Rhino wrapping machinery will  
pass the request for item "0" by  asking the NativeJavaObject to  
interpret it, and it tries to look up a method by that name on the  
underlying Java object, which doesn't exist...

I've introduced an additional check in RhinoWrapper that detects if  
the Rhino object is itself wrapper for something (implements  
org.mozilla.javascript.Wrapper), and if it is, unwrap() it and then re-
wrap what's inside it using BeansWrapper. Our Jython wrapper has a  
similar logic for detecting Jython-wrapped Java objects that implement  
FreeMarker interfaces.

You can try this JAR file: (it's 2.3.12 + all fixes we instituted  
since; it'll eventually become 2.3.13)
<http://freemarker.org:8085/download/FM-BRANCH23/artifacts/build-65/Library/freemarker.jar 
 >

Attila.

On 2008.04.12., at 18:16, Edwin S. Ramirez wrote:

> Thank you for taking a look, I appreciate any advice that you can give
> me.  The code is below, followed by the stack trace which shows a  
> couple
> of debug statements from JavaScript on the JavaScript object which
> implements the "TemplateSequenceModel" interface.  I am using Rhino  
> 1.7R1.
>
> JAVASCRIPT:
>
> function sequence(fdat) {
>     var obj = {};
>
>     obj.get = function(idx) {
>         return Packages.TemplateSequence.Model({f: "Rec# " + idx});
>     }
>
>     obj.size = function() {
>         return 5;
>     }
>
>     fdat.data = new JavaAdapter(Packages.TemplateSequence, obj);
>
>     debug(fdat.data.size());
>     debug(fdat.data.get(3));
>
>
>     writeln(getTemplate({tplname: "/Test/sequence.tpl", data: fdat}));
> }
>
> TEMPLATE:
>
> [#list data as d]
> ${d.f}<br/>
> [/#list]
>
> JAVA:
>
> import freemarker.template.*;
> import freemarker.ext.rhino.*;
>
> public class TemplateSequence implements TemplateSequenceModel {
>     static RhinoWrapper bw = new RhinoWrapper();
>
>     public TemplateSequence() {}
>
>     public TemplateModel get(int idx) {
>         System.out.println("In Get!");
>         return null;
>     }
>
>     public int size() { return 0; }
>
>     public static TemplateModel Model(Object sc) {
>         System.out.println("In Model!");
>         try {
>             return bw.wrap(sc);
>         } catch(Exception e) {
>             e.printStackTrace();
>         }
>         return null;
>     }
> }
>
> STACK TRACE:
> 5
> In Model!
> freemarker.ext.rhino.RhinoScriptableModel@5fa80aea
> org.mozilla.javascript.EvaluatorException: Java class "adapter1" has  
> no
> public instance field or method named "0". (lib/init.js#149)
>         at
> org
> .mozilla
> .javascript
> .DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:109)
>         at
> org.mozilla.javascript.Context.reportRuntimeError(Context.java:922)
>         at
> org.mozilla.javascript.Context.reportRuntimeError(Context.java:978)
>         at
> org.mozilla.javascript.Context.reportRuntimeError2(Context.java:948)
>         at
> org
> .mozilla
> .javascript.JavaMembers.reportMemberNotFound(JavaMembers.java:873)
>         at
> org.mozilla.javascript.NativeJavaObject.get(NativeJavaObject.java:117)
>         at
> org
> .mozilla
> .javascript.ScriptableObject.getProperty(ScriptableObject.java:1603)
>         at
> freemarker
> .ext.rhino.RhinoScriptableModel.get(RhinoScriptableModel.java:55)
>         at freemarker.core.LoopContext.runLoop(LoopContext.java:109)
>         at freemarker.core.Environment.process(Environment.java:376)
>         at  
> freemarker.core.ast.IteratorBlock.execute(IteratorBlock.java:97)
>         at freemarker.core.Environment.render(Environment.java:219)
>         at freemarker.core.Environment.process(Environment.java:194)
>         at freemarker.template.Template.process(Template.java:242)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
> sun
> .reflect
> .NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>         at
> sun
> .reflect
> .DelegatingMethodAccessorImpl
> .invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:585)
>         at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:160)
>         at
> org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:
> 243)
>         at
> org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:76)
>         at org.mozilla.javascript.gen.c1._c23(lib/init.js:149)
>         at org.mozilla.javascript.gen.c1.call(lib/init.js)
>         at
> org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:
> 97)
>         at org.mozilla.javascript.gen.c26._c1(<events/test.js>:23)
>         at org.mozilla.javascript.gen.c26.call(<events/test.js>)
>         at
> org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:
> 97)
>         at org.mozilla.javascript.gen.c29._c0(test:1)
>         at org.mozilla.javascript.gen.c29.call(test)
>         at
> org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:
> 401)
>         at
> org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:
> 3003)
>         at org.mozilla.javascript.gen.c29.call(test)
>         at org.mozilla.javascript.gen.c29.exec(test)
>         at  
> org.mozilla.javascript.Context.evaluateString(Context.java:1088)
>         at idcServer.catalyst.service(catalyst.java:66)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:45)
>         at
> winstone.ServletConfiguration.execute(ServletConfiguration.java:249)
>         at winstone.RequestDispatcher.forward(RequestDispatcher.java:
> 335)
>         at
> winstone
> .RequestHandlerThread.processRequest(RequestHandlerThread.java:244)
>         at  
> winstone.RequestHandlerThread.run(RequestHandlerThread.java:150)
>         at java.lang.Thread.run(Thread.java:595)
>
>
> Attila Szegedi wrote:
>> No specific experience, but I understand what you're saying. What's
>> the problem you're running into? Also, what Rhino version are you  
>> using?
>>
>> Attila.
>>
>> On 2008.04.11., at 21:22, Edwin S. Ramirez wrote:
>>> Hello *,
>>>
>>> I use FreeMarker with Rhino to present database information.  For  
>>> most
>>> queries it is fine to extract all the database records into an array
>>> and
>>> then use that in the template.  For some queries which return a very
>>> large data set, I would like to let the template engine retrieve the
>>> records from the database.
>>>
>>> I have a Javascript object which implements a "next" method (returns
>>> the
>>> next record as a hash) and a rows method (returns the record count).
>>>
>>> I know that I can create a template which uses these functions
>>> directly,
>>> but I would like to use the same template for arrays as well.
>>>
>>> In theory, I should be able to use JavaAdapter to create a
>>> TemplateSequenceModel implementation directly in Javascript.  But, I
>>> am
>>> running into problems.
>>>
>>> Does anybody have any experiences with something like this?
>>>
>>> Thanks,
>>> -Edwin S. Ramirez-




-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: Javascript - TemplateSequenceModel

Edwin S. Ramirez
Thanks for working on this.

I tried to use the jar that you provided but it produces an error as
soon as I try to generate any template.  The model used for the template
is a Rhino hash.

java.lang.NoSuchFieldError: instance
         at freemarker.ext.rhino.RhinoWrapper.wrap(RhinoWrapper.java:21)
         at
freemarker.ext.rhino.RhinoScriptableModel.get(RhinoScriptableModel.java:52)
         at
freemarker.core.Environment.getGlobalVariable(Environment.java:1057)
         at freemarker.core.Environment.getVariable(Environment.java:1043)
         at
freemarker.core.Identifier._getAsTemplateModel(Identifier.java:70)
         at
freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
         at
freemarker.core.DefaultToExpression._getAsTemplateModel(DefaultToExpression.java:100)
         at
freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
         at freemarker.core.Expression.getStringValue(Expression.java:93)
         at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
         at freemarker.core.Environment.visit(Environment.java:208)
         at freemarker.core.MixedContent.accept(MixedContent.java:92)
         at freemarker.core.Environment.visit(Environment.java:208)
         at freemarker.core.Environment.process(Environment.java:188)
         at freemarker.template.Template.process(Template.java:237)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:160)
         at
org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:243)
         at
org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:76)
         at org.mozilla.javascript.gen.c1._c24(lib/init.js:167)
         at org.mozilla.javascript.gen.c1.call(lib/init.js)

-Edwin S. Ramirez-

Attila Szegedi wrote:

> Hi,
>
> I've looked into it, and it's an interesting case. What happens here  
> is that Rhino generates a wrapper class that extends TemplateSequence  
> (which implements TemplateSequenceModel), and creates an instance of  
> it, but that's then further wrapped into a Rhino "NativeJavaObject",  
> which is a wrapper for a Java class. Our Rhino wrapping machinery will  
> pass the request for item "0" by  asking the NativeJavaObject to  
> interpret it, and it tries to look up a method by that name on the  
> underlying Java object, which doesn't exist...
>
> I've introduced an additional check in RhinoWrapper that detects if  
> the Rhino object is itself wrapper for something (implements  
> org.mozilla.javascript.Wrapper), and if it is, unwrap() it and then re-
> wrap what's inside it using BeansWrapper. Our Jython wrapper has a  
> similar logic for detecting Jython-wrapped Java objects that implement  
> FreeMarker interfaces.
>
> You can try this JAR file: (it's 2.3.12 + all fixes we instituted  
> since; it'll eventually become 2.3.13)
> <http://freemarker.org:8085/download/FM-BRANCH23/artifacts/build-65/Library/freemarker.jar 
>  >
>
> Attila.
>


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: Javascript - TemplateSequenceModel

Attila Szegedi-3
What's the Rhino version you use? I suspect it must be an oldish one,  
because this exception is thrown on accessing the static field  
"org.mozilla.javascript.Undefined.instance", and it exists since Rhino  
1.6R2, released in september 2005.

Note to Daniel: this doesn't affect releasing 2.3.13; our code has  
been working like this for ages and it is correct.

Attila.

On 2008.04.20., at 18:08, Edwin S. Ramirez wrote:

> Thanks for working on this.
>
> I tried to use the jar that you provided but it produces an error as
> soon as I try to generate any template.  The model used for the  
> template
> is a Rhino hash.
>
> java.lang.NoSuchFieldError: instance
>         at freemarker.ext.rhino.RhinoWrapper.wrap(RhinoWrapper.java:
> 21)
>         at
> freemarker
> .ext.rhino.RhinoScriptableModel.get(RhinoScriptableModel.java:52)
>         at
> freemarker.core.Environment.getGlobalVariable(Environment.java:1057)
>         at freemarker.core.Environment.getVariable(Environment.java:
> 1043)
>         at
> freemarker.core.Identifier._getAsTemplateModel(Identifier.java:70)
>         at
> freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
>         at
> freemarker
> .core
> .DefaultToExpression._getAsTemplateModel(DefaultToExpression.java:100)
>         at
> freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
>         at freemarker.core.Expression.getStringValue(Expression.java:
> 93)
>         at freemarker.core.DollarVariable.accept(DollarVariable.java:
> 76)
>         at freemarker.core.Environment.visit(Environment.java:208)
>         at freemarker.core.MixedContent.accept(MixedContent.java:92)
>         at freemarker.core.Environment.visit(Environment.java:208)
>         at freemarker.core.Environment.process(Environment.java:188)
>         at freemarker.template.Template.process(Template.java:237)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
> sun
> .reflect
> .NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>         at
> sun
> .reflect
> .DelegatingMethodAccessorImpl
> .invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:585)
>         at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:160)
>         at
> org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:
> 243)
>         at
> org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:76)
>         at org.mozilla.javascript.gen.c1._c24(lib/init.js:167)
>         at org.mozilla.javascript.gen.c1.call(lib/init.js)
>
> -Edwin S. Ramirez-
>
> Attila Szegedi wrote:
>> Hi,
>>
>> I've looked into it, and it's an interesting case. What happens here
>> is that Rhino generates a wrapper class that extends TemplateSequence
>> (which implements TemplateSequenceModel), and creates an instance of
>> it, but that's then further wrapped into a Rhino "NativeJavaObject",
>> which is a wrapper for a Java class. Our Rhino wrapping machinery  
>> will
>> pass the request for item "0" by  asking the NativeJavaObject to
>> interpret it, and it tries to look up a method by that name on the
>> underlying Java object, which doesn't exist...
>>
>> I've introduced an additional check in RhinoWrapper that detects if
>> the Rhino object is itself wrapper for something (implements
>> org.mozilla.javascript.Wrapper), and if it is, unwrap() it and then  
>> re-
>> wrap what's inside it using BeansWrapper. Our Jython wrapper has a
>> similar logic for detecting Jython-wrapped Java objects that  
>> implement
>> FreeMarker interfaces.
>>
>> You can try this JAR file: (it's 2.3.12 + all fixes we instituted
>> since; it'll eventually become 2.3.13)
>> <http://freemarker.org:8085/download/FM-BRANCH23/artifacts/build-65/Library/freemarker.jar
>>>
>>
>> Attila.




-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: Javascript - TemplateSequenceModel

Edwin S. Ramirez
I am using Rhino 1.7R1.

Thanks,
-esr-

Attila Szegedi wrote:

> What's the Rhino version you use? I suspect it must be an oldish one,  
> because this exception is thrown on accessing the static field  
> "org.mozilla.javascript.Undefined.instance", and it exists since Rhino  
> 1.6R2, released in september 2005.
>
> Note to Daniel: this doesn't affect releasing 2.3.13; our code has  
> been working like this for ages and it is correct.
>
> Attila.
>
> On 2008.04.20., at 18:08, Edwin S. Ramirez wrote:
>
>> Thanks for working on this.
>>
>> I tried to use the jar that you provided but it produces an error as
>> soon as I try to generate any template.  The model used for the  
>> template
>> is a Rhino hash.
>>
>> java.lang.NoSuchFieldError: instance
>>         at freemarker.ext.rhino.RhinoWrapper.wrap(RhinoWrapper.java:
>> 21)
>>         at
>> freemarker
>> .ext.rhino.RhinoScriptableModel.get(RhinoScriptableModel.java:52)
>>         at
>> freemarker.core.Environment.getGlobalVariable(Environment.java:1057)
>>         at freemarker.core.Environment.getVariable(Environment.java:
>> 1043)
>>         at
>> freemarker.core.Identifier._getAsTemplateModel(Identifier.java:70)
>>         at
>> freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
>>         at
>> freemarker
>> .core
>> .DefaultToExpression._getAsTemplateModel(DefaultToExpression.java:100)
>>         at
>> freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
>>         at freemarker.core.Expression.getStringValue(Expression.java:
>> 93)
>>         at freemarker.core.DollarVariable.accept(DollarVariable.java:
>> 76)
>>         at freemarker.core.Environment.visit(Environment.java:208)
>>         at freemarker.core.MixedContent.accept(MixedContent.java:92)
>>         at freemarker.core.Environment.visit(Environment.java:208)
>>         at freemarker.core.Environment.process(Environment.java:188)
>>         at freemarker.template.Template.process(Template.java:237)
>>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>         at
>> sun
>> .reflect
>> .NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>         at
>> sun
>> .reflect
>> .DelegatingMethodAccessorImpl
>> .invoke(DelegatingMethodAccessorImpl.java:25)
>>         at java.lang.reflect.Method.invoke(Method.java:585)
>>         at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:160)
>>         at
>> org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:
>> 243)
>>         at
>> org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:76)
>>         at org.mozilla.javascript.gen.c1._c24(lib/init.js:167)
>>         at org.mozilla.javascript.gen.c1.call(lib/init.js)
>>
>> -Edwin S. Ramirez-
>>
>> Attila Szegedi wrote:
>>> Hi,
>>>
>>> I've looked into it, and it's an interesting case. What happens here
>>> is that Rhino generates a wrapper class that extends TemplateSequence
>>> (which implements TemplateSequenceModel), and creates an instance of
>>> it, but that's then further wrapped into a Rhino "NativeJavaObject",
>>> which is a wrapper for a Java class. Our Rhino wrapping machinery  
>>> will
>>> pass the request for item "0" by  asking the NativeJavaObject to
>>> interpret it, and it tries to look up a method by that name on the
>>> underlying Java object, which doesn't exist...
>>>
>>> I've introduced an additional check in RhinoWrapper that detects if
>>> the Rhino object is itself wrapper for something (implements
>>> org.mozilla.javascript.Wrapper), and if it is, unwrap() it and then  
>>> re-
>>> wrap what's inside it using BeansWrapper. Our Jython wrapper has a
>>> similar logic for detecting Jython-wrapped Java objects that  
>>> implement
>>> FreeMarker interfaces.
>>>
>>> You can try this JAR file: (it's 2.3.12 + all fixes we instituted
>>> since; it'll eventually become 2.3.13)
>>> <http://freemarker.org:8085/download/FM-BRANCH23/artifacts/build-65/Library/freemarker.jar
>>> Attila.
>
>
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> Don't miss this year's exciting event. There's still time to save $100.
> Use priority code J8TL2D2.
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel