You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Ugo Cei <ug...@apache.org> on 2004/09/30 11:42:09 UTC

Rhino beans

A little question for any Rhino gurus out there. Assuming you have a 
Javascript prototype defined like this (and assuming this is sensible, 
since my knowledge of JS is quite limited):

function PropertyHello() {
	this.message = "hello world";
}

PropertyHello.prototype.sayHello = function() {
	return this.message;
}

would it be possible to have the 'message' property be accessible via 
regular Java reflection. In other words, would it be possible to have 
this prototype behave like a Javabean:

public class PropertyHello {
   private String message = "hello world";
   public String getMessage() { return message; }
   public void setMessage(String m) { message = m; }
}

In my case, the getter and setter methods would be called via 
reflection.

	Ugo

-- 
Ugo Cei - http://beblogging.com/

Re: Rhino beans

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Ugo Cei wrote:

> Il giorno 30/set/04, alle 12:52, Vadim Gritsenko ha scritto:
> 
>> Probably not much help, but PropertyHello JS Bean will be seen from 
>> Java code as org.mozilla.javascript.Scriptable. If you can plug it in 
>> into BeanUtils, than you can use BeanUtils.
> 
> 
> Please explain what you mean by "plug it into BeanUtils" :-)

Hm, after looking at it, it seems that BeanUtils has no pluggable introspection. 
So (IMHO) you only other option is to implement JSWrapDynaBean (see WrapDynaBean 
for inspirations) and wrap each JS object into it when passing to the Java code.

Vadim


Re: Rhino beans

Posted by Ugo Cei <ug...@apache.org>.
Il giorno 30/set/04, alle 12:52, Vadim Gritsenko ha scritto:

> Probably not much help, but PropertyHello JS Bean will be seen from 
> Java code as org.mozilla.javascript.Scriptable. If you can plug it in 
> into BeanUtils, than you can use BeanUtils.

Please explain what you mean by "plug it into BeanUtils" :-)

	Ugo

-- 
Ugo Cei - http://beblogging.com/

Re: Rhino beans

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Ugo Cei wrote:

> A little question for any Rhino gurus out there. Assuming you have a 
> Javascript prototype defined like this (and assuming this is sensible, 
> since my knowledge of JS is quite limited):
> 
> function PropertyHello() {
>     this.message = "hello world";
> }
> 
> PropertyHello.prototype.sayHello = function() {
>     return this.message;
> }
> 
> would it be possible to have the 'message' property be accessible via 
> regular Java reflection. In other words, would it be possible to have 
> this prototype behave like a Javabean:
> 
> public class PropertyHello {
>   private String message = "hello world";
>   public String getMessage() { return message; }
>   public void setMessage(String m) { message = m; }
> }
> 
> In my case, the getter and setter methods would be called via reflection.

Probably not much help, but PropertyHello JS Bean will be seen from Java code as 
org.mozilla.javascript.Scriptable. If you can plug it in into BeanUtils, than 
you can use BeanUtils.

Vadim