husted 2002/12/28 14:28:27 Modified: doc/userGuide index.xml building_view.xml Log: Move 3.3.1 into Howto as "Building an ActionForm". Move 3.3.6 up as 3.3.1. Revision Changes Path 1.25 +1 -2 jakarta-struts/doc/userGuide/index.xml Index: index.xml =================================================================== RCS file: /home/cvs/jakarta-struts/doc/userGuide/index.xml,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- index.xml 27 Dec 2002 02:38:43 -0000 1.24 +++ index.xml 28 Dec 2002 22:28:27 -0000 1.25 @@ -82,12 +82,11 @@ <li><a href="building_view.html#i18n">3.2 Internationalization</a></li> <li><a href="building_view.html#form_beans">3.3 Forms and FormBean Interactions</a> <ul> - <li><a href="building_view.html#forms">3.3.1 Building Forms With Struts</a></li> + <li><a href="building_view.html#indexed">3.3.1 Indexed & Mapped Properties</a></li> <li><a href="building_view.html#form_input">3.3.2 Input Field Types Supported</a></li> <li><a href="building_view.html#presentation_tags">3.3.3 Other Useful Presentation Tags</a></li> <li><a href="building_view.html#form_validation">3.3.4 Automatic Form Validation</a></li> <li><a href="building_view.html#struts_validator">3.3.5 Struts Validator</a></li> - <li><a href="building_view.html#indexed">3.3.6 Indexed & Mapped Properties</a></li> </ul></li> <li><a href="building_view.html#other_presentations">3.4 Other Presentation Techniques</a> <ul> 1.25 +27 -282 jakarta-struts/doc/userGuide/building_view.xml Index: building_view.xml =================================================================== RCS file: /home/cvs/jakarta-struts/doc/userGuide/building_view.xml,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- building_view.xml 28 Dec 2002 21:53:15 -0000 1.24 +++ building_view.xml 28 Dec 2002 22:28:27 -0000 1.25 @@ -272,276 +272,39 @@ handle the incoming files. Struts handles these "multipart" forms in a way identical to building normal forms. - In the next section, we will cover using Struts to create a simple login - form, and also a simple mulitpart form. </p> - -</section> - -<section name="3.3.1 Building Forms With Struts" href="forms"> - - <p> - A complete example of a login form will illustrate how Struts - 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> - -<hr/> - -<pre><code><![CDATA[ -<%@ page language="java" %> -<%@ taglib -uri="/WEB-INF/struts-html.tld" -prefix="html" %> -<%@ -taglib uri="/WEB-INF/struts-bean.tld" -prefix="bean" %> -<html:html> -<head> -<title> -<bean:message key="logon.title"/> -</title> -</head> -<body bgcolor="white"> -<html:errors/> -<html:form action="/logon" focus="username"> -<table border="0" width="100%"> -<tr> -<th align="right"> -<bean:message key="prompt.username"/> -</th> -<td align="left"> -<html:text -property="username" -size="16"/> -</td> -</tr> -<tr> -<th align="right"> -<bean:message key="prompt.password"/> -</th> -<td align="left"> -<html:password -property="password" -size="16"/> -</td> -</tr> -<tr> -<td align="right"> -<html:submit> -<bean:message key="button.submit"/> -</html:submit> -</td> -<td align="right"> -<html:reset> -<bean:message key="button.reset"/> -</html:reset> -</td> -</tr> -</table> -</html:form> -</body> -</html:html> -]]></code></pre> - -<hr/> - - <p> - The following items illustrate the key features of form handling in Struts, - based on this example: - </p> - - <ul> - - <li> - The <code>taglib</code> directive tells the JSP page compiler where to - find the <i>tag library descriptor</i> for the Struts tag library. - In this case, we are using <code>bean</code> as the prefix that - identifies tags from the struts-bean library, and "html" as the prefix - that identifies tags from the struts-html library. - Any desired prefix can be used. - </li> - - <li> - This page uses several occurrences of the - <b>message</b> tag to look up internationalized - message strings from a <code>MessageResources</code> object containing - all the resources for this application. - For this page to work, the following message keys must be defined in - these resources: - - <ul> - - <li> - <b>logon.title</b> - Title of the logon page - </li> - - <li> - <b>prompt.username</b> - A "Username:" prompt string - </li> - - <li> - <b>prompt.password</b> - A "Password:" prompt string - </li> - - <li> - <b>button.submit</b> - "Submit" for the button label - </li> - - <li> - <b>button.reset</b> - "Reset" for the button label - </li> - - </ul> - - When the user logs on, the application can store a <code>Locale</code> - object in the user's session. - This <code>Locale</code> will be used to select messages in the - appropriate language. - This makes it easy to implement giving the user an option to switch - languages -- simply change the stored <code>Locale</code> object, and - all messages are switched automatically. - </li> - - <li> - The <b>errors</b> tag displays any error messages that have been - stored by a business logic component, or nothing if no errors have been - stored. - This tag will be described further below. - </li> - - <li> - The <b>form</b> tag renders an HTML <code><form></code> element, - based on the specified attributes. - It also associates all of the fields within this form with a - <code>ActionForm</code> bean - [<code>org.apache.struts.action.ActionForm</code>]. - The tag looks up the <code>/logon</code> action mapping in the Struts - configuration. - The <code>logon</code> mapping tells the tag that the form bean is - stored in the session context under the key <code>logonForm</code>. - The Struts developer provides the Java implementation of the - ActionForm bean, subclassing the Struts class <code>ActionForm</code> - (see <a href="building_controller.html#action_form_classes">Building - Controller</a> components). - This bean is used to provide initial values for all of the input - fields that have names matching the property names of the bean. - If an appropriate bean is not found, a new one will be created - automatically, using the Java class name specified through the - action mapping. - </li> - - <li> - The form bean can also be specified in the tag by providing - <code>name</code> and <code>type</code> attributes. But most often, - everything is specified in the - <a href="building_controller.html#config">Struts Configuration - File</a>. - </li> - - <li> - The <b>text</b> tag renders an HTML <code><input></code> - element of type "text". - In this case, the number of character positions to occupy on the - browser's screen has been specified as well. - When this page is executed, the current value of the - <code>username</code> property of the corresponding bean (that is, - the value returned by <code>getUsername</code>). - </li> - - <li> - The <b>password</b> tag is used similarly. - The difference is that the browser will echo asterisk characters, - instead of the input value, as the user types their password. - </li>. - - <li> - The <b>submit</b> and<b>reset</b> tags generate the corresponding - buttons at the bottom of the form. - The text labels for each button are created using message tags, - as with the prompts, so that these values are internationalized. - </li> - - </ul> - - <p> - Handling multipart forms is also easy. - Obviously when you create a multipart form you're creating a form that - has at least one input of type "file". - The first step to creating a multipart form is to utilize the struts-html - taglib to create the presentation page: - </p> - -<hr/> - -<pre><code><![CDATA[ -<%@page language="java"> -<%@taglib uri="/WEB-INF/struts-html.tld" - prefix="html"> -<html:form -action="uploadAction.do" -enctype="multipart/form-data"> -Please Input Text: -<html:text property="myText"> -Please Input The File You Wish to Upload: -<html:file property="myFile"> -<html:submit /> -</html:form> -]]></code></pre> - -<hr/> - + <p> - The next step is to create your ActionForm bean: + For an example of using Struts to create a simple login form, + see the "<a href="../faqs/actionForm.html"> + Buiding an ActionForm Howto</a>". </p> +</section> -<hr/> -<pre><code><![CDATA[ -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; -} -} -]]></code></pre> - -<hr/> +<section name="3.3.1 Indexed & Mapped Properties" href="indexed"> <p> - Look at the Javadocs for - <code><a href="../api/org/apache/struts/upload/FormFile.html"> - FormFile</a></code> to see the methods it exposes to manipulate files in - file uploading. - Also look at the Javadocs for - <a href="http://jakarta.apache.org/struts/api/org/apache/struts/action/ActionServlet.html"> - ActionServlet</a> and - <a href="http://jakarta.apache.org/struts/api/org/apache/struts/action/ActionMapping.html"> - ActionMapping</a> for the various parameters you can specify to change - how files are uploaded. - Basically in your <code>execute</code> method in your action class you - would call <code>((UploadForm) form).getMyFile()</code> to retrieve the - FormFile and do what you want with it. + Property references in JSP pages using the Struts framework can reference + Java Bean properties as described in the JavaBeans specification. + Most of these references refer to "scalar" bean properties, referring to + primitive or single Object properties. + However, Struts, along with the Jakarta Commons Beanutils library, allow + you to use property references which refer to individual items in an array, + collection, or map, which are represented by bean methods using + well-defined naming and signature schemes. </p> +<p> + Documentation on the Beanutils package can be found at + <a href="http://jakarta.apache.org/commons/beanutils/api/index.html"> + http://jakarta.apache.org/commons/beanutils/api/index.html</a>. + More information about using indexed and mapped properties in Struts can + be found in the FAQ describing <a + href="../faqs/indexedprops.html"><i>Indexed Properties, Mapped Properties, + and Indexed Tags</i></a>. +</p> </section> <section name="3.3.2 Input Field Types Supported" href="form_input"> @@ -774,30 +537,12 @@ </li> </ol> </p> -</section> - -<section name="3.3.6 Indexed & Mapped Properties" href="indexed"> - + <p> - Property references in JSP pages using the Struts framework can reference - Java Bean properties as described in the JavaBeans specification. - Most of these references refer to "scalar" bean properties, referring to - primitive or single Object properties. - However, Struts, along with the Jakarta Commons Beanutils library, allow - you to use property references which refer to individual items in an array, - collection, or map, which are represented by bean methods using - well-defined naming and signature schemes. + For more about the Struts Validator, see the + <a href="./dev_validator.html">Developers Guide</a>. </p> - -<p> - Documentation on the Beanutils package can be found at - <a href="http://jakarta.apache.org/commons/beanutils/api/index.html"> - http://jakarta.apache.org/commons/beanutils/api/index.html</a>. - More information about using indexed and mapped properties in Struts can - be found in the FAQ describing <a - href="../faqs/indexedprops.html"><i>Indexed Properties, Mapped Properties, - and Indexed Tags</i></a>. -</p> + </section> <section name="3.4 Other Presentation Techniques" href="other_presentations">
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>