Hi Linda,
>   Thank you for you assistance.
>   
You are very welcome, glad that I could help a little bit.

>   I modified my code for the approach using manager.registerBean() :
>    
>   BSFManager manager = new BSFManager();
>   manager.registerBean( "myBeanName", new MyBeanClazz("str for regBean");
>   manager.exec( "javascript", "test", 0,0, 
> "bsf.lookupBean(\"myBeanName\").myMethod();" );
>    
>   This time it works and printed out the string in the console. Thanks.
>   
Fine.

>   It looks that the BSFManager defaultly declared a bean "bsf" so the script 
> can always use it just like a predefined object in the javascript.
>   
It is put into the global context by the Javascript engine.

>   But for my ObjectRegistery approach, even I tried to call bsf.lookupBean in 
> the script code, it still doesn't work, anything still missing here?
>   
Hmm, did you set the the ObjectRegistry object to your BSFManager's
instance?

Something along the lines:

    bm=new org.apache.bsf.BSFManager();
    // ... do whatever you need to do (setup, invoking scripsts, maybe
    nothing, whatever)

    or=new org.apache.bsf.ObjectRegistry();
    // or if you want to use bm's ObjectRegistry object as a parent:
    or=new org.apache.bsf.ObjectRegistry(bm.getObjectRegistry());
    // do whatever you need to do with "or" (registering objects for the
    scripts)....

    bm.setObjectRegistry(or);    // now set "bm" to the new
    ObjectRegistry object "or"
    // continue to invoke scripts

HTH,

---rony

Reply via email to