struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Bosmans <peter.bosm...@mail.khlim.be>
Subject How do struts manage this
Date Thu, 03 Jul 2003 13:16:02 GMT
I'm playing with a demo running with struts, jboss and a mysql database.
This example extracts data from a database and dump this in a table on 
my browser.
But i don't understand one thing.
In the action method they set an attribute "employees" with the 
collection employees. Which is filled only with the emp_id numbers (see 
employee EJB). In struts-config.xml is "employeeviewsucces" forwarded to 
"employeeviewsucces.jsp".
In employeeviewsucces.jsp they refer to this "employees". How can get 
these logic:iterate the other data from the database. (During debuging i 
found out that the EJB methods were called, but i don't understand who 
and why these methods are called. I see no link between the EJBmethods 
and the jsp calls.
Can somebody give me e little bit more explanation please or a hint 
where i can find more explanation about this.
Thanks in advance.
Peter

Here a snip of  the struts action-code :
 .....
   try {
     InitialContext jndiContext = new InitialContext(env);
     Object ref = jndiContext.lookup("Employee");
     EmployeeHome home= 
(EmployeeHome)PortableRemoteObject.narrow(ref,EmployeeHome.class);
     Collection employees = home.findAll();
     session.setAttribute("employees", employees);
     } catch (Exception e) {
     return (mapping.findForward("employeeviewfailure"));
   }
   return (mapping.findForward("employeeviewsuccess"));
 }
.....

Here's a the findall method of the Employee EJB
.....
public Collection ejbFindAll() {
   Vector employeeKeys = new Vector();
   String sqlString = "select EMP_ID from EMPLOYEE";
   try {
     Statement s = connection.createStatement();
     ResultSet rs = s.executeQuery(sqlString);
     while (rs.next()) {
       employeeKeys.addElement(new Integer(rs.getInt("EMP_ID")));
     }
    rs.close();
   } catch (SQLException e) {
     System.out.println("An SQL Exception occurred while querying result 
set of employee");
   }
   return employeeKeys;
 }
.....

employeeviewsuccess if forwarded to employeeviewsucces.jsp. Here's the 
snip of the code i don't understand.
.....
   <logic:present name="employees" scope="session">
    <logic:iterate id="currentEmployee" name="employees" scope="session">
     <tr>
      <td>
       <bean:write name="currentEmployee" property="employeeid"/>
      </td>
      <td>
       <bean:write name="currentEmployee" property="firstname"/>
      </td>
      <td>
       <bean:write name="currentEmployee" property="lastname"/>
      </td>
      <td>
       <bean:write name="currentEmployee" property="extension"/>
      </td>
      <td>
       <bean:write name="currentEmployee" property="department"/>
      </td>
      <td>
       <bean:write name="currentEmployee" property="city"/>
      </td>
      <td>
       <a href="employeedelete.do?id=<bean:write
        name="currentEmployee" property="employeeid"/>">Delete</a>
      </td>
      <td>
       <a href="employeemodifysetup.do?id=<bean:write
        name="currentEmployee" property="employeeid"/>">Modify</a>
      </td>
     </tr>
    </logic:iterate>
   </logic:present>
.....





---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message