The next example shows how you might write an ATG Servlet Bean that dumps information about any bean. This example servlet bean, named BeanInfoDroplet
, sets a parameter named beaninfo
with the values of the BeanInfo
of the bean passed to it:
public class BeanInfoDroplet extends DynamoServlet { public void service(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse) throws ServletException, IOException { Object bean = pRequest.getObjectParameter("bean"); try { pRequest.setParameter("beaninfo", DynamicBeans.getBeanInfo(bean)); } catch (IntrospectionException ex) { logError(ex); } pRequest.serviceParameter("output", pRequest, pResponse); } }
You might invoke the example BeanInfoDroplet
servlet bean in a JavaServer Page like the following example. You pass the name of the bean in the bean
input parameter. This page then displays the beaninfo
parameter in a table:
<%@ taglib uri="/dspTaglib" prefix="dsp" %> <dsp:page> <html> <head><title>BeanInfo</title></head> <body><h1>BeanInfo</h1> <dsp:droplet name="BeanInfoDroplet"> <dsp:param bean="/atg/userprofiling/Profile" name="bean"/> <dsp:oparam name="output"> <b><dsp:valueof param="beaninfo.name"/></b><p> <i><dsp:valueof param="beaninfo.shortDescription"/></i><p> <dsp:droplet name="ForEach"> <dsp:param name="array" param="beaninfo.propertyDescriptors"/> <dsp:oparam name="outputStart"> <table> <tr> <td>Property</td> <td>Type</td> <td>Value</td> <td>Readable?</td> <td>Writable?</td> <td>Required?</td> <td>Expert?</td> <td>Hidden?</td> <td>Preferred?</td> <td>Description</td> </tr> </dsp:oparam> <dsp:oparam name="output"> <tr> <td><dsp:valueof param="element.name"/></td> <td><dsp:valueof param="element.propertyType.name"/></td> <td> <dsp:valueof param='<%="bean." + request.getParameter("element.name")%>'/> </td> <td><dsp:valueof param="element.readable"/></td> <td><dsp:valueof param="element.writable"/></td> <td><dsp:valueof param="element.required"/></td> <td><dsp:valueof param="element.expert"/></td> <td><dsp:valueof param="element.hidden"/></td> <td><dsp:valueof param="element.preferred"/></td> <td><dsp:valueof param="element.shortDescription"/></td> <tr> </dsp:oparam> <dsp:oparam name="outputEnd"> </table> </dsp:oparam> </dsp:droplet> </dsp:oparam> </dsp:droplet> </body></html> </dsp:page>