I am fairly new to struts and am trying to interate though an Oracle result set; the SCOTT/TIGER emp table. I saw this on another forum, but cannot get it to work. If someone knows of a better way or how to get this to work, I am all ears:
Regards, ed
Java Action code (works fine)
stmt = conn.createStatement(); rset = stmt.executeQuery("SELECT EMPNO, ENAME FROM scott.emp"); rsdc = new RowSetDynaClass(rset); request.setAttribute("customers", rsdc); ...
JASP code:
<logic:iterate id="customer" name="customers" property="rows" scope="request"> <br>This is filler text <bean:write name="customer" property="EMPNO"/> <bean:write name="customer" property="ENAME"/> </logic:iterate >
Error:
javax.servlet.ServletException: No getter method for property EMPNO of bean customer org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779) org.apache.jsp.masterlist_jsp._jspService(masterlist_jsp.java:215) ...
The trouble with this code is that your variable "customer" is of type DynaBean, and DynaBean is not a true javaBean. There is no getEMPNO() method but only a get(String) method. My suggestion would be to create an Employee bean. You could then create a list of Employee beans and use the BeanUtils.copyProperties() method to copy the properties of the DynaBean to the Employee bean.