Re: Beans constructed with BCEL makes html:option throw ClassCastExceptioninStruts 1.0.2

2002-04-30 Thread Thorbjoern Andersen

James Mitchell wrote:
 With all the features of Struts 1.1 and 1.1-beta, why do you continue in
 this direction?
 
 Am I missing something?
 
 I can create a 5 page wizard and never write a single line of ActionForm
 code.
 
 Help me if I am misunderstanding.

I got around the symptoms so now it works by having a static ClassLoader 
instead of one per instance.  Beats me why.

I continue doing this since I do not need this for creating the actual 
form-beans (for which it would be less useful), but for providing a 
glue-layer between the databases we use, and the various presentation 
utilities that expect beans, like struts and the display taglib.  This 
glue-layer should accept any ResultSet and allow access to the 
individual fields, which my solution do reasonably well.

If you know of such an OpenSource product, I would love to hear it.  Am 
I really the only one who needs this?

 P.S.  Shouldn't this be asked in the [EMAIL PROTECTED]???

Most likely, except that it is rather low traffic.  I just gathered that 
the people who wrote the Struts bean manipulation utilities were more 
likely to linger here.

My apologies for using the list for these questions, but I do not 
currently have a colleague to discuss the matters with.
-- 
   Thorbjoern Ravn Andersen
   Scandiatransplant, c/o Christian Mondrup
   89 49 53 01
   http://biobase.dk/~tra


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Beans constructed with BCEL makes html:option throw ClassCastExceptionin Struts 1.0.2

2002-04-29 Thread Thorbjoern Andersen

As mentioned on this list previously I have, with great labour, written 
a class which generates beans on the fly using BCEL based on a 
user-provided Property mapping field-named to field-types.

This now works well, but my first attempt on using these beans with 
Struts have failed with the error message quoted at the end of this 
message, which indicates to me that I have missed some part here.

I have an ArrayList of my beans, where this code works nicely:

{
  java.util.ArrayList al = 
abf.createBeanArrayList(stmt.executeQuery( select distinct donor_ab0 
from ab0_rules order by donor\
_ab0));
  pageContext.setAttribute( bloodTypes, al);
  java.util.ListIterator i = al.listIterator();
  while( i.hasNext()) {
 Object o = i.next();
 out.println( o +  :  + BeanUtils.describe( o) + br);
  }
}

and prints out the following:

org.scandiatransplant.anonybeans.Xcc416f1298d2f3e4.3e9584e0f1d96d@415727 
: {donor_ab0=0, class=class 
org.scandiatransplant.anonybeans.Xcc416f1298d2f3e4.3e9584e0f1d96d}

org.scandiatransplant.anonybeans.Xcc416f1298d2f3e4.3e9584e0f1d96d@c0fc8e 
: {donor_ab0=A, class=class 
org.scandiatransplant.anonybeans.Xcc416f1298d2f3e4.3e9584e0f1d96d}
...

But when I want to use it with Struts 1.0.2 in the construct

...
html:select property=bloodType
html:options collection=bloodTypes property=donor_ab0
labelProperty=donor_ab0/
/html:select
...

it fails as described.  If it is related, I have found that I can easily 
  cast the result of bean.newInstance() to an Object, but not to a 
Class.

Any thoughts on how to fix this would be appreciated.  I am so close to 
making this work :-)




The error message is as follows

java.lang.IllegalArgumentException: java.lang.ClassCastException@4649ed
at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at 
org.apache.struts.util.PropertyUtils.getSimpleProperty(PropertyUtils.java:717)
at 
org.apache.struts.util.PropertyUtils.getNestedProperty(PropertyUtils.java:426)
at org.apache.struts.util.PropertyUtils.getProperty(PropertyUtils.java:453)
at org.apache.struts.taglib.html.OptionsTag.doEndTag(OptionsTag.java:202)
at _k__jsp._jspService(/k1/k.jsp:146)
at com.caucho.jsp.JavaPage.service(JavaPage.java:74)
at com.caucho.jsp.Page.subservice(Page.java:485)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:179)
at com.caucho.server.http.Invocation.service(Invocation.java:288)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:132)
at com.caucho.server.http.ServletServer.serviceTop(ServletServer.java:937)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:213)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:158)
at com.caucho.server.TcpConnection.run(TcpConnection.java:140)
at java.lang.Thread.run(Thread.java:536)




-- 
   Thorbjoern Ravn Andersen
   Scandiatransplant, c/o Christian Mondrup
   89 49 53 01
   http://biobase.dk/~tra


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: Creating beans dynamically from byte code in a byte[] with ClassLoader.defineClass- how to do it right?

2002-04-24 Thread Thorbjoern Andersen

Craig R. McClanahan wrote:

Subject: Re: Creating beans dynamically from byte code in a byte[] with 
ClassLoader.defineClass - how to do it right?
From: JM [EMAIL PROTECTED]
 ===
Absolutely, how did ya do it?
 
 
 One approach to dynamic class generation would be to use the BCEL package
 at Jakarta:
 
   http://jakarta.apache.org/bcel

Which was what I ended up doing, with a syntetic class name based on the 
MD5 sum of the field names and types.

 A second option is to take advantage of the new DynaActionForm
 capabilities in Struts 1.1-b1 -- you declare the form bean properties in
 struts-config.xml and don't actually have to write the form bean class
 unless you need a custom reset() or validate() method.  Even if you do
 need those, they are the only methods you have to write.

I wanted something that was able to beanify a JDBC ResultSet, without 
any external configuration what so ever, in order to basically return a 
SQL-query as an ArrayList of Beans.  I am just wrapping it up so I can 
start using it for populating our search forms (we basically need to do 
up to 10 seperate SQL-queries to populate all our drop down boxes), and 
then I need a permission to publish what I wrote - unfortunately that 
might take some time, but I expect I will be allowed to, and then I will 
submit it for Jakarta.

-- 
   Thorbjoern Ravn Andersen
   Scandiatransplant, c/o Christian Mondrup
   89 49 53 01
   http://biobase.dk/~tra


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: Creating beans dynamically from byte code in a byte[] with ClassLoader.defineClass- how to do it right?

2002-04-20 Thread Thorbjoern Andersen

Thorbjørn Ravn Andersen (Scandiatransplant) wrote:

I have spent some time lately figuring out how I can generate beans
on-the-fly with fields completely specified at run-time, since this would
be an enourmeous help when working with JDBC and Struts in an informal
matter (which is why I ask here :-)

I have now made it work with generating code automatically.  There are 
still some rough edges, but I can now take a JDBC-request, generate a 
bean for all the fields, and forward it to Struts without having to 
create beans in advance.  It complements the BeanUtils very well.  

Is this interesting to anybody but me :-) ?  

-- 
  Thorbjoern




--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]