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_pt
CreateActions_zh
CreateManager
CreateManager_es
SpringControllers_ko
ValidationAndList




JSPWiki v2.2.33

[RSS]


Hide Menu

CreateActions


Difference between version 51 and version 50:

At line 12 changed 1 line.
* <span style="color: green">__Spring MVC:__ [Creating Controllers and JSPs|SpringControllers]</span>
* <span style="color: green">__Spring MVC:__</span> [Creating Controllers and JSPs|SpringControllers]
At line 58 changed 2 lines.
</div>
* Copy personForm.jsp to web/personForm.jsp. Copy PersonFormList.jsp to web/personList.jsp. ''Notice that each of the new filename's first character is lowercase.''
</div>
* Copy personForm.jsp to web/pages/personForm.jsp. Copy PersonFormList.jsp to web/pages/personList.jsp. ''Notice that each of the new filename's first character is lowercase.''
At line 61 changed 1 line.
We copy the JSPs to the ''web'' folder instead of ''web/pages'' because the ''pages'' directory ends up in ''WEB-INF/pages'' when the application is packaged into a [WAR|http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/WCC3.html#69310] file. This is a [recommended practice|http://husted.com/struts/catalog.html] when building secure web applications.
%%note If you want to customize the CSS for a particular page, you can add &lt;body id="pageName"/> to the top of the file. This will be slurped up by SiteMesh and put into the final page. You can then customize your CSS on a page-by-page basis using something like the following:
{{{body#pageName element.class { background-color: blue }}}
%%
At line 63 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.''
* Add keys in ApplicationResources_en.properties the titles and headings in the JSPs
In the generated JSPs, there are two keys for the title (top of the browser window) and the header (heading in the page). We now need to add these two keys (personDetail.title and personDetail.heading) to ApplicationResources_en.properties.
At line 65 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'').
Open web/WEB-INF/classes/ApplicationResources_en.properties and add the following to the bottom of the file:
At line 67 removed 5 lines.
All this is to say that __putting the personForm.jsp in the ''web'' folder will allow us to view it without creating an Action to get to it__.
At this point, you won't be able to view the JSP in your browser because the &lt;html:form&gt; tag in personForm.jsp has ''action="editPerson"'' - 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__.
Then, start Tomcat and then go to [http://localhost:8080/appfuse/personForm.jsp]. This will result in the following error:
At line 73 changed 1 line.
javax.servlet.jsp.JspException: Cannot retrieve mapping for action /editPerson
# -- person detail page --
personDetail.title=Person Detail
personDetail.heading=Person Information
At line 75 removed 1 line.
Therefore, we need to create an Action for this JSP, and we should probably create a Test before we write our Action.
At line 76 added 3 lines.
%%__NOTE:__ Just above, we added "personForm.*" keys to this file, so why do I use personForm ''and'' personDetail? The best reason is because it gives a nice separation between form labels and text on the page. Another reason is because all the *Form.* give you a nice representation of all the fields in your database. I recently had a client who wanted all fields in the database searchable. This was fairly easy to do. I just looked up all the keys in ApplicationResources.properties which contained "Form." and then put them into a drop-down. On the UI, the user was able to enter a search term and select the column they wanted to search. I was glad I followed this Form vs. Detail distinction on that project!%%
At line 84 removed 2 lines.
When we do create an Action (in [step 4|4]), we're only going to create an __execute__ method, rather than all the different CRUD methods. So let's just test that method to start.
At line 119 removed 2 lines.
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Back to CreateActions, or to the Page History.