View Full Version : reflection of java classes
jocsch
11-04-2004, 11:59 PM
Hi there,
not sure if there is a developer reading these threads, but I wanted to ask if there is a way around the limitiation, that if I get a return object from a javarpc I only see the public fields of this object in laszlo.
It does not seem that laszlo recognizes the javabean style with private fields and public getters and setters.
That's pretty annoying as it forces to write a DTO class for nearly every java class because nobody is using public fields...
Greetings,
Markus
pablo
11-08-2004, 11:05 AM
Hi Markus,
We're hoping to improve EJB support in a future release.
http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=957&highlight=EJB
pablo
jocsch
11-08-2004, 01:11 PM
Hi pablo nice to hear.
To be honest the only thing I'm missing in the moment is the reflection of java beans.
I'm not such a big fan of EJBs and for sure don't want to be forced to use an EJB backend just because of laszlo. Think about the movement towards the lightweight frameworks in the moment.
Please keep the functionality in POJOs so people have the choice to use them in an EJB environment or not.
I think it's quite good that you load the classes directly. What would be very cool is ServletContextAware interface that the classes could implement and which allows them to retrieve the servlet context. That would make integration in other frameworks (like spring) quite easy.
Greetings,
Markus
pablo
11-08-2004, 01:53 PM
Hi Markus,
I've filed a todo for better java beans supports.
I think it's quite good that you load the classes directly. What would be very cool is ServletContextAware interface that the classes could implement and which allows them to retrieve the servlet context. That would make integration in other frameworks (like spring) quite easy.
Not sure if this is what you're looking for, but you can pass HttpServletRequest and HttpServletResponse as the last two parameters of a method. This should give you access to the servlet context and http session. For example:
void myFunc1(int a, ..., int n, HttpServletRequest req) {
HttpSession sess = req.getSession();
ServletContext ctxt = sess.getServletContext();
// ...
}
void myFunc2(int a, ..., int n, HttpServletResponse res) {
// ...
}
void myFunc3(int a, ..., int n, HttpServletRequest req, HttpServletResponse res) {
//...
}
If both the servlet request and servlet response are specified as parameters, the response must follow the request.
As far as the client is concerned, HttpServletRequest and HttpServletResponse parameters are transparent.
(Note: this example uses the raw javarpc proxy functions that take two parameters: an array of parameters and a delegate to receive the return value.)
javarpcobj.proxy.myFunc1([ a, ..., N], delegate);
javarpcobj.proxy.myFunc2([ a, ..., N], delegate);
javarpcobj.proxy.myFunc3([ a, ..., N], delegate);
The sessionrpc and webapprpc take advantage of this feature. I've attached the java code that webapprpc uses. You can view the webapprpc LZX code at lps/components/rpc/webapprpc.lzx.
I'll make sure this is properly documented in a future release.
Cheers,
pablo
jocsch
11-21-2004, 10:05 AM
I changed the javabeans behaviour myself. Find the patch attached. I also posted this to the dev mailinglist. Maybe you find it useful and apply it against cvs.
-----------------list posting---------------
Hi list,
do you ever used the <javarpc> calls and inspected the laszlo converted return object? Laszlo converts, at least in the 2.2 release (I don't have tried 3.0 yet, maybe someone changed this behaviour already), only the public fields of an object into xml and send them to the swf client.
That's pretty annoying because nobody (or not many) in the OO world use public member fields. Instead it's normal to provide access via public getter and setter methods. See the javabeans standard.
Because I didn't want to write a DTO for every object I have, I modified the sourcecode of the LZReturnObject to inspect the given return object with the help of the jakarta-commons beanutils ( http://jakarta.apache.org/commons/beanutils/ )
Now the LZReturnObject converts the object according to the javabean specifications (that means it uses the public getters instead of accessing the fields).
Maybe a developer can check this patch and apply it to cvs?
To compile the changed file it's neccessary to copy the commons-beanutils.jar to the WEB-INF/lib directory (I use version 1.6.1)
Greetings,
Markus Joschko
I added a patch against the 2.2 version of LZReturnObject.java
ldblaauw
06-14-2005, 12:49 PM
Hi all,
Well the attachment below seems gone and not sure yet
what laszlo 3 does with it. But as far as i can read the solution in the original post this is indead the way to send plain vanilla javabeans across the line with all their properties properly exposed on the client side.
Any answers / solution here ?
Greetings
Leo
Originally posted by jocsch
I changed the javabeans behaviour myself. Find the patch attached. I also posted this to the dev mailinglist. Maybe you find it useful and apply it against cvs.
pablo
06-14-2005, 01:00 PM
Hi Leo,
The change was patched in the platform and to get javabean values, set the objectreturntype attribute of javarpc to 'javabean'.
See the reference page at:
http://www.laszlosystems.com/lps-3.0/docs/reference/javarpc.html
pablo
ldblaauw
06-14-2005, 01:04 PM
Hi pablo,
Excelent, just what i was hoping for since that enables us to reuse our existing domain model into the laszlo based front end !
Greetz
Leo
Originally posted by pablo
Hi Leo,
The change was patched in the platform and to get javabean values, set the objectreturntype attribute of javarpc to 'javabean'.
See the reference page at:
http://www.laszlosystems.com/lps-3.0/docs/reference/javarpc.html
pablo
ldblaauw
06-14-2005, 01:24 PM
Pablo,
In the doc link it states that default is pojo i assume it is identical to javabean....
But anyway i will do some testing to see how it goes.
Greetz
Leo
Originally posted by pablo
Hi Leo,
The change was patched in the platform and to get javabean values, set the objectreturntype attribute of javarpc to 'javabean'.
See the reference page at:
http://www.laszlosystems.com/lps-3.0/docs/reference/javarpc.html
pablo
pablo
06-14-2005, 01:38 PM
Hi Leo,
The only difference between javabean and pojo returns are that javabean returns only members that have getters, whereas pojo will return all members that are public.
pablo
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.