It should be similar to something I put together a while back for dealing with
accessing public static final fields from a JSP without resorting to
request-time expressions:
public static Map getConstantFieldsAsMap(Class cls)
throws IllegalAccessException {
Map propMap = new HashMap();
String className = cls.getName();
Field[] allFields = cls.getDeclaredFields();
for (int i = 0, n = allFields.length; i < n; i++) {
Field f = allFields[i];
int mods = f.getModifiers();
if (Modifier.isPublic(mods) &&
Modifier.isStatic(mods) &&
Modifier.isFinal(mods)) {
String name = f.getName();
Object value = f.get(null);
propMap.put(name, value);
}
}
return Collections.unmodifiableMap(propMap);
}
Quoting [EMAIL PROTECTED]:
>
> hmm... very interesting idea.
> And if I'm lucky, there could already be something like that
> written(recursively or iterativly runs through an object and puts field
> values in a map.)
> The only hickup would be to convert basic types to Object representation.
> But that shouldn't be too hard. Maybe something already doing that in
> beanutils.
>
> I'll look at that,
> thx
>
> -Henrik Bentel
>
>
>
>
>
>
> Kris Schneider <[EMAIL PROTECTED]> on 07/09/2003 01:20:36 PM
>
> Please respond to "Struts Users Mailing List"
> <[EMAIL PROTECTED]>
>
> To: Struts Users Mailing List <[EMAIL PROTECTED]>
> cc:
>
> Subject: RE: bean:write and c:out only takes proper javabeans?
>
> You could use reflection to populate a map with the fields' values (using
> the
> field names for keys).
>
> Quoting [EMAIL PROTECTED]:
>
> >
> > ok, just to clarify. I was hoping to use the IDLEntities straight in my
> JSP
> > pages. There's so many of them that I was looking for a way to avoid
> > creating "client-side" javabean representations of all the IDLEntities.
> > There's a lot of them. And I mean A LOT. And the IDL to Java
> compiler(idlj)
> > creates the objects with public fields and no getter and setters. So I'm
> > somewhat stuck.
> >
> > Guess I'll look to some Corba message boards for insight to what people
> > usually does.
> >
> > -Henrik Bentel
> >
> >
> >
> >
> >
> >
> > Stephen Brown <[EMAIL PROTECTED]> on 07/09/2003 12:05:15 PM
> >
> > Please respond to "Struts Users Mailing List"
> > <[EMAIL PROTECTED]>
> >
> > To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]>
> > cc:
> >
> > Subject: RE: bean:write and c:out only takes proper javabeans?
> >
> > The only way to do this is the use getter and setter methods with
> JavaBean
> > naming conventions. This should in no way interfere with a Corba
> backend,
> > Corba can be used pretty much just like EJB. The tags use reflection,
> but
> > just to find appropriately named getter methods - the Java conventions
> say
> > to make the fields private, you should follow the base Java conventions
> > http://java.sun.com/docs/codeconv/.
> >
> > > -----Original Message-----
> > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> > > Sent: July 9, 2003 12:08 PM
> > > To: [EMAIL PROTECTED]
> > > Subject: bean:write and c:out only takes proper javabeans?
> > >
> > >
> > > Does the bean write tag and the c:out tag (JSTL) only accept
> > > object that
> > > adhere to the Javabean specification?
> > >
> > > I have objects with public fields(no getter or setter) and
> > > objects inside
> > > objects all public(again no getter or setter).
> > > But if I try to do somthing like(in JSTL) <C:out value="
> > > ${resultBean.intMember}"/> where intMember is just a public
> > > int field, I
> > > get the following exception:
> > > org.apache.jasper.JasperException: An error occurred while evaluating
> > > custom action attribute "value" with value "${resultBean.intMember}":
> > > Unable
> > > to find a value for "intMember" in object of class
> > > "beantest.testBean1"
> > > using
> > > operator "." (null)
> > > at
> > > org.apache.jasper.servlet.JspServletWrapper.service(JspServlet
> > > Wrapper.java:254)
> > >
> > >
> > > Yes, idealy I should use proper javabeans, but in this case
> > > my struts app
> > > is interfacing with a CORBA based backend, and all result-structures
> > > comming back are IDLEntities with public fields(the backend is an old
> > > C-based app with nothing but heavily nested enums and structs
> > > and whatnot.
> > > ).
> > >
> > > So my assumption was that the tags used reflection on fields
> > > so I could
> > > just write value="${result.innerResult.wayInnerResult.innerLong}"
> > > Are there any ways of doing this?
> > >
> > > thanks
> > > Henrik Bentel
>
> --
> Kris Schneider <mailto:[EMAIL PROTECTED]>
> D.O.Tech <http://www.dotech.com/>
--
Kris Schneider <mailto:[EMAIL PROTECTED]>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]