This tutorial will show you how to create an Action, a JUnit Test (using StrutsTestCase) , and a JSP for the form. The Action we create will talk to the PersonManager we created in the Creating Managers tutorial. This tutorial will simplify everything - we will not actually be rendering any data making the UI look pretty. The next tutorial will show you how to integrate your new JSP into your webapp.
I will tell you how I do stuff in the Real World in text like this.
Let's get started by creating a new Action and JSP in AppFuse's architecture.
[4] Display the JSP in a browser and run the ActionTest
Here's a quick-n-dirty how to. We're creating a new Action/JSP for the "Position" entity in this example:
Generate your Struts' ActionForms by executing "ant ejbdoclet" from the command-line
Generate a skeleton JSP using the strutsgen tool in the tools folder:
From the command-line, navigate to "tools/strutsgen"
Execute "ant gen -Dform.name=PositionForm" to generate two files in tools/strutsgen/build: PositionForm.properties (labels for your form elements) and PositionForm.jsp (skeleton JSP file)
Copy the contents of PositionForm.properties into web/WEB-INF/classes/ApplicationResources.properties.
Copy PositionForm.jsp to web/positionForm.jsp
Create a new Struts Action in src/web. We called it PositionAction.java. Look in ResumeAction.java for the XDoclet javadocs at the beginning of the class. Use these as an example to create a /savePosition action-mapping.
Delete all methods in PositionAction.java (if you used ResumeAction.java as a template). Find and replace [Rr]esume with [Pp]osition.
Override the execute method and put a debugging statement into the method body to verify we're hitting it. Something like: System.out.println("entering execute method");
Edit web/positionForm.jsp so the form's action="savePosition"
Run "ant deploy" to deploy the updated application to Tomcat.
This should bring up the JSP, with a simple form in it. Click the button and you should see "entering execute method" in your Tomcat console. If so - nice work!
Next up - integrating positionForm.jsp with Tiles, putting some meat into the Action's execute method, creating an ActionTest, replacing execute with different CRUD methods (add, edit, search), customizing the JSP so it looks good and finally - write a WebTest to test the JSPs functionality (or doing it via the browser).