You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by H....@MI.unimaas.nl on 2004/06/18 11:37:04 UTC

JXTemplate introspection problem - PLEASE HELP

Guys,

I hope some of you can help, because I'm stuck and cannot figure out what to
do to get this solved. I've posted this on the userlist as well but got no
response, so I figured that it is probably too much related to the Cocoon
internals for a "regular" user to answer. I'm trying my luck here.

Problem:

I have two classes with more or less similar functionality. Both have a
method getFormattedValue, but in my JXTemplate only one produces a correct
output. After two days of debugging I find that the introspection finds the
method through JXTemplateGenerator.JSIntrospector.getPropertyGet in the
correct class, but fails to do so in the other class.
When I call the getFormattedValue method of the faulty class in my
flowscript I get correct output.

So

class CorrectClass () {
  Object value;
....
  public String getFormattedValue() {
     return doSomething(value);
  }
}

class FaultyClass() {
  SomeClass value;
...
  public String getFormattedValue() {
     return doSomeFormatting(value);
  }
}

jxtemplate:

<p>${obj.formattedValue}</p>


flowscript:

function works() {
 someValue = "correctTest";

 CorrectClass obj = new Packages.mypackage.CorrectClass();
 obj.setValue(someValue);
 print("correct class: " + obj.getFormattedValue()) -> correctTest

 var viewdata = {obj : obj};
 cocoon.sendPage("myTemplate", viewdata); -> <p>correctTest</p>
}

function doesNotWork() {
 someValue = "correctTest";

 FaultyClass obj2 = new Packages.mypackage.FaultyClass();
 obj2.setValue(someValue);
 print("faulty class: " + obj.getFormattedValue()) -> correctTest}

 var viewdata = {obj : obj2};
 cocoon.sendPage("myTemplate", viewdata); -> <p></p>
}

Anyone?

Thanks.

Bye,

Helma van der Linden

Re: JXTemplate introspection problem - PLEASE HELP

Posted by Sylvain Wallez <sy...@apache.org>.
H.vanderLinden@MI.unimaas.nl wrote:

>Guys,
>
>I hope some of you can help, because I'm stuck and cannot figure out what to
>do to get this solved. I've posted this on the userlist as well but got no
>response, so I figured that it is probably too much related to the Cocoon
>internals for a "regular" user to answer. I'm trying my luck here.
>  
>

Helma, I just fixed a weird bug in Rhino+cont related to Java objects 
introspection. That problem occured on objects instance of a private of 
package-private class, which were turned into JS objects having no 
properties at all.

Don't know if your classes are private or package-private, but you may 
want to try the latest rhino jar, committed a few minutes ago.

Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }


Re: JXTemplate introspection problem - PLEASE HELP

Posted by Niklas Eklund <ni...@curalia.se>.
H.vanderLinden@MI.unimaas.nl wrote:

<snip />
> flowscript:
> 
> function works() {
>  someValue = "correctTest";
> 
>  CorrectClass obj = new Packages.mypackage.CorrectClass();
>  obj.setValue(someValue);
>  print("correct class: " + obj.getFormattedValue()) -> correctTest
> 
>  var viewdata = {obj : obj};
>  cocoon.sendPage("myTemplate", viewdata); -> <p>correctTest</p>
> }
> 
> function doesNotWork() {
>  someValue = "correctTest";
> 
>  FaultyClass obj2 = new Packages.mypackage.FaultyClass();
>  obj2.setValue(someValue);
>  print("faulty class: " + obj.getFormattedValue()) -> correctTest}
                             ^^^
This might not be the problem, but your FaultyClass could be faulty if 
you used cut'n'paste from your actual code. The line above uses 
obj.getFormattedValue() and not obj2.getFormattedValue() which could 
give the illusion that your FaultyClass is correct even if it isn't, if 
obj is global.

Regards,
  Niklas

>  var viewdata = {obj : obj2};
>  cocoon.sendPage("myTemplate", viewdata); -> <p></p>
> }
> 
> Anyone?
> 
> Thanks.
> 
> Bye,
> 
> Helma van der Linden