Raible's Wiki

Raible Designs
Wiki Home
News
Recent Changes

AppFuse

Homepage
  - Korean
  - Chinese
  - Italian
  - Japanese

QuickStart Guide
  - Chinese
  - French
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish
  - Japanese

User Guide
  - Korean
  - Chinese

Tutorials
  - Chinese
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish

FAQ
  - Korean

Latest Downloads

Other Applications

Struts Resume
Security Example
Struts Menu

Set your name in
UserPreferences


Referenced by
Articles
Articles_cn
Articles_pt
Articles_zh
CreateActions
CreateActions_pt
CreateActions_zh
SpringControllerUnit...
SpringControllers_ko
ValidationAndListSpr...
...and 1 more




JSPWiki v2.2.33

[RSS]


Hide Menu

SpringControllers


Difference between version 3 and version 2:

At line 6 changed 1 line.
This tutorial will show you how to create two Spring Controllers - one for a list screen, and one for the form. It'll also demonstrate writing a JUnit Test to test the Controllers, and two JSPs. The Controller we create will talk to the PersonManager we created in the [Creating Managers|CreateManager] tutorial. This tutorial will simplify everything - we will not actually be rendering any data or making the UI look pretty. The [next tutorial|ConfiguringTiles] will show you how to integrate your new JSPs into your webapp.
This tutorial will show you how to create a Spring Controller and JSP. It'll also demonstrate writing a JUnit Test to test the Controller. The Controller we create will talk to the PersonManager we created in the [Creating Managers|CreateManager] tutorial. This tutorial will simplify everything - we will not actually be rendering any data or making the UI look pretty. The [next tutorial|ConfiguringTiles] will show you how to integrate your new JSPs into your webapp.
At line 10 changed 1 line.
Let's get started by creating a new Controller and JSP in AppFuse's architecture. If you haven't installed the Spring MVC module at this point, do so by running "ant install-springmvc".
Let's get started by creating a new Controller and JSP in AppFuse's architecture. If you haven't installed the Spring MVC module at this point, do so by running ''ant install-springmvc''.
At line 19 changed 1 line.
In this step, we'll generate a ''skeleton'' or our JSP for displaying information from the PersonForm. I say ''skeleton'' because it'll just be the <form> itself. It will contain table rows and Struts' <html:text> tags for each property in PersonForm.java. The tool that we use to do this was written by [Erik Hatcher|http://www.blogscene.org/erik/]. It's basically just a single class (FormTagsHandler.java) and a couple of XDoclet templates (FormKeys.xdt and StrutsForm_jsp.xdt). All these files are located in extras/jspgen.
In this step, we'll generate a ''skeleton'' or our JSP for displaying information from the Person object. I say ''skeleton'' because it'll just be the <form> itself. It will contain table rows and Struts' <html:text> tags for each property in Person.java. The tool that we use to do this was written by [Erik Hatcher|http://www.blogscene.org/erik/]. It's basically just a single class (FormTagsHandler.java) and a couple of XDoclet templates (FormKeys.xdt and Form_jsp.xdt). All these files are located in extras/viewgen.
At line 23 changed 4 lines.
* Execute __ant webdoclet__ - this generates the PersonForm.java from the Person.java POJO.
* From the command-line, navigate to "extras/jspgen"
* Execute __ant -Dform.name=PersonForm__ to generate three files in extras/jspgen/build:
** PersonForm.properties (labels for your form elements)
* From the command-line, navigate to "extras/viewgen"
* Execute __ant -Dform.name=Person__ to generate three files in extras/viewgen/build:
** Person.properties (labels for your form elements)
At line 28 changed 2 lines.
** PersonFormList.jsp (skeleton JSP file for viewing a list of People)
* Copy the contents of PersonForm.properties into web/WEB-INF/classes/ApplicationResources.properties. Here is an example of what you might add to ApplicationResources.properties:
** personList.jsp (skeleton JSP file for viewing a list of People)
* Copy the contents of Person.properties into web/WEB-INF/classes/ApplicationResources.properties. Here is an example of what you might add to ApplicationResources.properties:
At line 33 changed 3 lines.
personForm.firstName=First Name
personForm.id=Id
personForm.lastName=Last Name
person.firstName=First Name
person.id=Id
person.lastName=Last Name
At line 42 changed 1 line.
;: ''The container provides security for all files below WEB-INF. This applies to client requests, but not to forwards from the ActionServlet. Placing all JSPs below WEB-INF ensures they are only accessed through Actions, and not directly by the client or each other. This allows security to be moved up into the Controller, where it can be handled more efficiently, and out of the base presentation layer.''
;: ''The container provides security for all files below WEB-INF. This applies to client requests, but not to forwards from the DispatchServlet. Placing all JSPs below WEB-INF ensures they are only accessed through Controllers, and not directly by the client or each other. This allows security to be moved up into the Controller, where it can be handled more efficiently, and out of the base presentation layer.''
At line 44 changed 1 line.
The web application security for AppFuse specifies that all *.html url-patterns should be protected. This guarantees 1) all Actions are protected, and 2) you must go through an Action to get to a JSP (or at least the ones in ''pages'').
The web application security for AppFuse specifies that all *.html url-patterns should be protected. This guarantees 1) all Controllers are protected, and 2) you must go through a Controller to get to a JSP (or at least the ones in ''pages'').
At line 48 changed 1 line.
At this point, you won't be able to view the JSP in your browser because the <html:form> tag in personForm.jsp has ''action="savePerson"'' - and this action-mapping doesn't exist (yet) in struts-config.xml. You can try it yourself (cd ../.. first) by setting up AppFuse on Tomcat using __ant setup-db setup-tomcat deploy__.
At this point, you won't be able to view the JSP in your browser because the <html:form> tag in personForm.jsp has ''action="editPerson"'' - and this url-mapping doesn't exist (yet) in action-servlet.xml. You can try it yourself (cd ../.. first) by setting up AppFuse on Tomcat using __ant setup-db setup-tomcat deploy__.

Back to SpringControllers, or to the Page History.