husted 01/01/21 20:44:08 Modified: src/doc/userGuide building_view.xml building_model.xml building_controller.xml Log: Submitted by Ted Husted. Reformat example code in smaller font to enable printing (at least in Landscape mode). Revision Changes Path 1.12 +24 -47 jakarta-struts/src/doc/userGuide/building_view.xml Index: building_view.xml =================================================================== RCS file: /home/cvs/jakarta-struts/src/doc/userGuide/building_view.xml,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- building_view.xml 2001/01/21 12:57:51 1.11 +++ building_view.xml 2001/01/22 04:44:07 1.12 @@ -96,16 +96,12 @@ <li><b>MyResources.properties</b> - Contains the messages in the default language for your server. If your default language is English, you might have an entry like this: - <pre> - prompt.hello=Hello - </pre></li> + <code>prompt.hello=Hello</code></li> <li><b>MyResources_xx.properties</b> - Contains the same messages in the language whose ISO language code is "xx" (See the ResourceBundle Javadoc page for a link to the current list). For a French version of the message shown above, you would have this entry: - <pre> - prompt.hello=Bonjour - </pre> + <code>prompt.hello=Bonjour</code> You can have resource bundle files for as many languages as you need.</li> </ul> @@ -133,25 +129,27 @@ <p> Fulfilling this expectation is tedious and cumbersome when coding with standard HTML and JSP pages. For example, an input element for a - <code>username</code> field might look like this (in JSP) + <code>username</code> field might look like this (in JSP): + </p> - -<pre> - <input type="text" name="username" - value="<%= loginBean.getUsername() %>"> -</pre> - + <p> + <code><input type="text" name="username" + value="<%= loginBean.getUsername() %>"></code> + </p> + <p> which is difficult to type correctly, confuses HTML developers who are not knowledgeable about programming concepts, and can cause problems with HTML editors. Instead, Struts provides a comprehensive facility for building forms, based on the Custom Tag Library facility of JSP 1.1. The case above would be rendered like this using Struts: - -<pre> - <html:text property="username"/> -</pre> + </p> + + <p> + <code><html:text property="username"/></code> + </p> + <p> with no need to explicitly refer to the JavaBean from which the initial value is retrieved. That is handled automatically by the framework. </p> @@ -171,21 +169,15 @@ makes dealing with forms much less painful than using straight HTML and standard JSP facilities. Consider the following page (based on the example application included with Struts) named <code>logon.jsp</code>: - </p> - -<pre> -<%@ page language="java" %> + </p> +<pre><font size="-1"><%@ page language="java" %> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> - - <html> <head> <title><bean:message key="logon.title"/></title> <body bgcolor="white"> - <html:errors/> - <html:form name="logonForm" action="logon.do"> <table border="0" width="100%"> <tr> @@ -218,11 +210,8 @@ </tr> </table> </html:form> - </body> -</html> -</pre> - +</html></font></pre> <p> The following items illustrate the key features of form handling in Struts, based on this example: @@ -291,52 +280,41 @@ </p> <p> -<pre> -<%@page language="java"> - +<pre><font size="-1"><%@page language="java"> <%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"> - <html:form action="uploadAction.do"> Please Input Text: <html:text property="myText"><br /> Please Input The File You Wish to Upload:<br /> <html:file property="myFile"><br /> <html:submit /> </html:form> -</pre> +</font></pre> </p> <p> The next step is to create your ActionForm bean: </p> <p> -<pre> -import javax.servlet.http.HttpServletRequest; +<pre><font size="-1">import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; import org.apache.struts.upload.FormFile; - public class UploadForm extends ActionForm { - protected String myText; protected FormFile myFile; - public void setMyText(String text) { myText = text; } - public String getMyText() { return myText; } - public void setMyFile(FormFile file) { myFile = file; } - public FormFile getMyFile() { return myFile; } -} -</pre> +}</font></pre> </p> <p> @@ -419,10 +397,9 @@ offers an additional facility to validate the input fields it has received. To utilize this feature, override the following method in your ActionForm class: - <pre> - public ActionErrors validate(ActionMapping mapping, + <pre><font size="-1">public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) - </pre> + </font></pre> </p> <p> 1.9 +8 -13 jakarta-struts/src/doc/userGuide/building_model.xml Index: building_model.xml =================================================================== RCS file: /home/cvs/jakarta-struts/src/doc/userGuide/building_model.xml,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- building_model.xml 2001/01/21 12:57:51 1.8 +++ building_model.xml 2001/01/22 04:44:07 1.9 @@ -59,20 +59,18 @@ a bean stored as a request attribute in a servlet like this: </p> -<pre> - MyCart mycart = new MyCart(...); - request.setAttribute("cart", mycart); -</pre> + <p><code>MyCart mycart = new MyCart(...);<br /> + request.setAttribute("cart", mycart); + </code></p> <p> is immediately visible to a JSP page which this servlet forwards to, using a standard action tag like this: </p> - <pre> - <jsp:useBean id="cart" scope="request" + <p><code><jsp:useBean id="cart" scope="request"<br /> class="com.mycompany.MyApp.MyCart"/> - </pre> + </code></p> </section> <section name="2.3 ActionForm Beans" href="actionform"> @@ -232,14 +230,12 @@ from within a Action perform method. </p> <p> -<pre> - public ActionForward perform(ActionMapping mapping, +<pre><font size="-1">public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { try { - DataSource dataSource = servlet.findDataSource(null); - + DataSource dataSource = servlet.findDataSource(null); Connection myConnection = dataSource.getConnection(); //do what you wish with myConnection } @@ -251,8 +247,7 @@ //sure the connection is closed myConnection.close(); } - } -</pre> + }</font></pre> </p> <p align="center"> 1.8 +25 -42 jakarta-struts/src/doc/userGuide/building_controller.xml Index: building_controller.xml =================================================================== RCS file: /home/cvs/jakarta-struts/src/doc/userGuide/building_controller.xml,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- building_controller.xml 2001/01/21 12:57:51 1.7 +++ building_controller.xml 2001/01/22 04:44:07 1.8 @@ -39,8 +39,7 @@ <p>The <code>Action</code> class defines two methods that could be executed depending on your servlet environment: -<pre> - public ActionForward perform(ActionMapping mapping, +<pre><font size="-1">public ActionForward perform(ActionMapping mapping, ActionForm form, ServletRequest request, ServletResponse response) @@ -51,7 +50,7 @@ HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException -</pre> +</font></pre> </p> <p> @@ -115,10 +114,8 @@ You should trap all such exceptions in the logic of your <code>perform()</code> method, and log them to the application logfile (along with the corresponding stack trace) by - calling: - <pre> - servlet.log("Error message text", exception); - </pre></li> + calling:<br /> + <code>servlet.log("Error message text", exception);</code></li> <li>As a general rule, allocating scarce resources and keeping them across requests from the same user (in the user's session) can cause scalability problems. You should strive to release such resources @@ -268,19 +265,15 @@ to illustrate the requirements. Note that the entries for all the other actions are left out: </p> -<pre> - <struts-config> +<pre><font size="-1"><struts-config> <form-beans> <form-bean name="logonForm" type="org.apache.struts.example.LogonForm"> - </form-beans> - + </form-beans> <global-forwards type="org.apache.struts.action.ActionForward"> <forward name="logon" path="/logon.jsp" redirect="false" /> - </global-forwards> - - <action-mappings> - + </global-forwards> + <action-mappings> <action path="/logon" type="org.apache.struts.example.LogonAction" name="logonForm" @@ -290,8 +283,7 @@ validate="true" /> </action-mappings> </struts-config> -</pre> - +</font></pre> <p> First the form bean is defined. A basic bean of class "org.apache.struts.example.LogonForm" is mapped to the logical name "logonForm". This name is used as a session or request attribute @@ -318,8 +310,7 @@ of struts-config.xml: </p> <p> -<pre> - <struts-config> +<pre><font size="-1"><struts-config> <data-sources> <data-source autoCommit="false" description="Example Data Source Description" @@ -331,7 +322,7 @@ user="myusername"/> </data-sources> </struts-config> -</pre> +</font></pre> </p> <p> For information on how to retrieve the data source, see the @@ -354,8 +345,7 @@ <p> Add an entry defining the action servlet itself, along with the appropriate initialization parameters. Such an entry might look like this: -<pre> - <servlet> +<pre><font size="-1"><servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> @@ -376,7 +366,7 @@ </init-param> <load-on-startup>2</load-on-startup> </servlet> -</pre> +</font></pre> </p> <p> @@ -475,19 +465,17 @@ path part) with a particular value to be passed to this servlet. Such an entry might look like this: </p> -<pre> - <servlet-mapping> +<pre><font size="-1"><servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>/execute/*</url-pattern> </servlet-mapping> -</pre> +</font></pre> <p> which means that a request URI to match the <code>/logon</code> path - described earlier might look like this: - <pre> - http://www.mycompany.com/myapplication/execute/logon - </pre> + described earlier might look like this:</p> + <p> + <code> http://www.mycompany.com/myapplication/execute/logon</code> </p> <p> @@ -502,20 +490,17 @@ to the <code>*.jsp</code> pattern so that it is called to process every JSP page that is requested. To use the <code>*.do</code> extension (which implies "do something"), the mapping entry would look like this: -<pre> - <servlet-mapping> +<pre><font size="-1"><servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> -</pre> +</font></pre> </p> <p> and a request URI to match the <code>/logon</code> path described - earlier might look like this: - <pre> - http://www.mycompany.com/myapplication/logon.do - </pre> + earlier might look like this:<br /> + <code> http://www.mycompany.com/myapplication/logon.do</code> </p> </section> @@ -547,10 +532,8 @@ <p> Below is how you would define all taglibs for use within your application, - in reality you would only specify the taglib's that your application will use: - -<pre> - <taglib> + in reality you would only specify the taglib's that your application will use: +<pre><font size="-1"><taglib> <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri> <taglib-location>/WEB-INF/struts-bean.tld</taglib-location> </taglib> @@ -566,7 +549,7 @@ <taglib-uri>/WEB-INF/struts-template.tld</taglib-uri> <taglib-location>/WEB-INF/struts-template.tld</taglib-location> </taglib> -</pre> +</font></pre> </p> <p>