Dear Wiki user, You have subscribed to a wiki page or wiki category on "Struts Wiki" for change notification.
The following page has been changed by MichaelJouravlev: http://wiki.apache.org/struts/StrutsQuickStart ------------------------------------------------------------------------------ == Employee list with pure JSP (Model 1) == Before the data list is displayed, it should be retrieved from a database and saved into appropriate J2EE scope like request, session or application. Then the list is iterated and its content is shown line by line. Notice JSTL 2.0 usage. + + inline:employee_list.gif {{{<%@ page import="java.util.ArrayList, model.EmployeeManager"%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> @@ -145, +147 @@ == Event handling in Struts: delete an employee == Now after you got the idea how Struts fits the servlet/JSP environment, let us improve our application. How about being able to delete an employee from the list? To do this we will change the JSP page, adding an "Operation" column and creating a "Delete" link for each table row. The link would contain employee ID. When clicked, the link will be processed by the same Action that displays the list. To distinguish the "Delete" command from the request to merely display the list, we will add a special parameter to the link. We will define this parameter as an event for this action in the {{{struts-config.xml}}} file, and we will redesign the Action class to perform employee removal code when this parameter is received. + + inline:employee_list_delete.gif + Here is modified EmployeeListAction class, notice that it extends EventDispatchAction class: {{{public class EmployeesListActionDelete extends EventDispatchAction { @@ -234, +239 @@ == Action interaction in Struts and form submission: view an employee == - Let us change the application to view an employee information in a separate form. To view an employee we will create a separate Action class, EmployeeActionView, which will handle "view" event: + Let us change the application to view an employee information in a separate form. + + inline:employee_list_view.gif + + inline:employee_view.gif + + To view an employee we will create a separate Action class, EmployeeActionView, which will handle "view" event: {{{/** * Action that displays an employee in a separate HTML form. @@ -385, +396 @@ == Data editing and full-blown CRUD application == - Now when we know how to view and delete an employee, let us add the missing parts: creation, update and saving of modified employee data. The EmployeeAction class handles "create", "view", "edit", "duplicate", "save", "delete" and "close" events, this is how it is configured: + Now when we know how to view and delete an employee, let us add the missing parts: creation, update and saving of modified employee data. + + inline:employee_list_crud.gif + + inline:employee_edit.gif + + The EmployeeAction class handles "create", "view", "edit", "duplicate", "save", "delete" and "close" events, this is how it is configured: {{{<action path = "/employeesListCRUD" type = "actions.EmployeesListAction"> @@ -403, +420 @@ <forward name = "finished" path = "/employeesListCRUD.do" redirect = "true"/> </action>}}} - The {{{EmployeeAction}}} class is not very complicated, but you better dowload the sample WAR file with the source code, and see it yourself. + The {{{EmployeeAction}}} class is not very complicated, but you better dowload the sample WAR file with the source code: attachment:crud.war.