You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Peter Bosmans <pe...@mail.khlim.be> on 2003/07/03 15:16:02 UTC
How do struts manage this
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
Re: How do struts manage this
Posted by Konstadinis Euaggelos <Va...@eurodyn.com>.
Collection employees = home.findAll();
This code returns a collection with Employes, LocalObject (you must read
about ejbs, there are a lot of books for this.)
The collection employees is not filled with emp_id but with EmployeeObject,
This object has all the properties of the Employee table(employeeid,
firstname, lastname, ....)
That the code below is OK, because the Object in the iterator has all this
properties.
<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"/>
If you have any question please ask..
Vangos.
----- Original Message -----
From: "Peter Bosmans" <pe...@khlimmer.khlim.be>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Thursday, July 03, 2003 3:16 PM
Subject: How do struts manage this
> 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
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org