Added: websites/production/struts/content/development/2.x/docs/struts-2-form-tags.html ============================================================================== --- websites/production/struts/content/development/2.x/docs/struts-2-form-tags.html (added) +++ websites/production/struts/content/development/2.x/docs/struts-2-form-tags.html Wed Jul 17 09:31:08 2013 @@ -0,0 +1,359 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<html> +<head> + <LINK type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css"> + <style type="text/css"> + .dp-highlighter { + width:95% !important; + } + </style> + <style type="text/css"> + .footer { + background-image: url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif'); + background-repeat: repeat-x; + background-position: left top; + padding-top: 4px; + color: #666; + } + </style> + <link href='http://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' /> + <link href='http://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' /> + <script src='http://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script> + <script src='http://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script> + + <script type="text/javascript"> + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all(); + </script> + <script type="text/javascript" language="javascript"> + var hide = null; + var show = null; + var children = null; + + function init() { + /* Search form initialization */ + var form = document.forms['search']; + if (form != null) { + form.elements['domains'].value = location.hostname; + form.elements['sitesearch'].value = location.hostname; + } + + /* Children initialization */ + hide = document.getElementById('hide'); + show = document.getElementById('show'); + children = document.all != null ? + document.all['children'] : + document.getElementById('children'); + if (children != null) { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + } + + function showChildren() { + children.style.display = 'block'; + show.style.display = 'none'; + hide.style.display = 'inline'; + } + + function hideChildren() { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + </script> + <title>Struts 2 Form Tags</title> +</head> +<body onload="init()"> +<table border="0" cellpadding="2" cellspacing="0" width="100%"> + <tr class="topBar"> + <td align="left" valign="middle" class="topBarDiv" align="left" nowrap> + <a href="home.html">Home</a> > <a href="tutorials.html">Tutorials</a> > <a href="getting-started.html">Getting Started</a> > <a href="struts-2-form-tags.html">Struts 2 Form Tags</a> + </td> + <td align="right" valign="middle" nowrap> + <form name="search" action="http://www.google.com/search" method="get"> + <input type="hidden" name="ie" value="UTF-8" /> + <input type="hidden" name="oe" value="UTF-8" /> + <input type="hidden" name="domains" value="" /> + <input type="hidden" name="sitesearch" value="" /> + <input type="text" name="q" maxlength="255" value="" /> + <input type="submit" name="btnG" value="Google Search" /> + </form> + </td> + </tr> +</table> + +<div id="PageContent"> + <div class="pageheader" style="padding: 6px 0px 0px 0px;"> + <!-- We'll enable this once we figure out how to access (and save) the logo resource --> + <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"--> + <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div> + <div style="margin: 0px 10px 8px 10px" class="pagetitle">Struts 2 Form Tags</div> + + <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;"> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=19300595"> + <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=19300595">Edit Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW"> + <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif" + height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a> + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a> + + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=19300595"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=19300595">Add Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=19300595"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add News"></a> + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=19300595">Add News</a> + </div> + </div> + + <div class="pagecontent"> + <div class="wiki-content"> + <div id="ConfluenceContent"><div class="panelMacro"><table class="infoMacro"><colgroup span="1"><col span="1" width="24"><col span="1"></colgroup><tr><td colspan="1" rowspan="1" valign="top"><img align="middle" src="https://cwiki.apache.org/confluence/images/icons/emoticons/information.gif" width="16" height="16" alt="" border="0"></td><td colspan="1" rowspan="1">The example code for this tutorial, form_tags, can be checked out from <a shape="rect" class="external-link" href="https://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2examples/">https://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2examples/</a>.</td></tr></table></div> + +<h3><a shape="rect" name="Struts2FormTags-Introduction"></a>Introduction</h3> +<p>In this tutorial we'll explore some of the other Struts 2 form controls. In our previous tutorials that explained how to use Struts 2 forms (<a shape="rect" href="processing-forms.html" title="Processing Forms">Processing Forms</a>, <a shape="rect" href="form-validation.html" title="Form Validation">Form Validation</a>, and <a shape="rect" href="message-resource-files.html" title="Message Resource Files">Message Resource Files</a>) we covered how to use the Struts 2 head, form, textfield controls and the key attribute. This tutorial will explore using the Struts 2 select, radio, checkbox, and checkboxlist form controls.</p> + +<div class="panelMacro"><table class="tipMacro"><colgroup span="1"><col span="1" width="24"><col span="1"></colgroup><tr><td colspan="1" rowspan="1" valign="top"><img align="middle" src="https://cwiki.apache.org/confluence/images/icons/emoticons/check.gif" width="16" height="16" alt="" border="0"></td><td colspan="1" rowspan="1">The <a shape="rect" class="external-link" href="http://struts.apache.org/mail.html">Struts 2 user mailing list</a> is an excellent place to get help. If you are having a problem getting the tutorial example applications to work search the Struts 2 mailing list. If you don't find an answer to your problem, post a question on the mailing list.</td></tr></table></div> + +<h3><a shape="rect" name="Struts2FormTags-ExampleApplication"></a>Example Application</h3> +<p>The example application that supports this tutorial shows how to use Struts 2 form tags so that a user can edit his information. The information that can be edited is encapsulated in an object of class Person. A Person object knows these things: first name, last name, favorite sport, gender, state of residency, is or is not over 21, and car models owned. </p> + +<p>To enable the user to edit his information that is stored in the Person object, we need to create a form like this one:</p> + +<p><span class="image-wrap" style=""><img src="struts-2-form-tags.data/Screen+shot+2010-04-25+at+8.39.59+AM.png" style="border: 0px solid black"></span></p> + +<p>The form allows the user to make changes. After submitting the form, the Struts 2 framework will update the state of the Person object.</p> + +<p>The first and last names are shown on the form (see edit.jsp) using the Struts 2 textfield tag, which we've discussed in previous tutorials. </p> + +<h3><a shape="rect" name="Struts2FormTags-Struts2SelectTag"></a>Struts 2 Select Tag</h3> +<p>A user can select one favorite sport from several choices. The example application uses the Struts 2 select tag to provide the list of options for the select box. </p> + +<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Struts 2 Select Tag</b></div><div class="codeContent panelContent"> +<script class="theme: Default; brush: html; gutter: false" type="syntaxhighlighter"><![CDATA[ + +<s:select key="personBean.sport" list="sports" /> + +]]></script> +</div></div> + +<p>In these form tags, we are using the key attribute as discussed in the <a shape="rect" href="message-resource-files.html" title="Message Resource Files">Message Resource Files</a> tutorial. The key attribute is used by the Struts 2 framework to determine values for the other attributes (e.g. label and value). We are also using a property file associated with the EditAction class to provide the label values based on the key attribute value (see the <a shape="rect" href="message-resource-files.html" title="Message Resource Files">Message Resource Files</a> tutorial for information on using Struts 2 property files). </p> + +<div class="panelMacro"><table class="infoMacro"><colgroup span="1"><col span="1" width="24"><col span="1"></colgroup><tr><td colspan="1" rowspan="1" valign="top"><img align="middle" src="https://cwiki.apache.org/confluence/images/icons/emoticons/information.gif" width="16" height="16" alt="" border="0"></td><td colspan="1" rowspan="1">Note that there are many attributes for the Struts 2 form tags, most of which mirror the HTML attributes associated with the tags. You can read about all the attributes for a Struts 2 form tag by consulting the Struts 2 documentation.</td></tr></table></div> + +<p>The value of the list attribute of the Struts 2 select tag is used by the framework to determine what method of the action class to call in order to create the option values. In our example application, the list attribute value of "sports" results in the framework calling the getSports method of class EditAction. That method returns a String array containing "football", "baseball", and "basketball". Those values are used to create the option tags inside the select tag. </p> + +<p>The Struts 2 framework determines which option is preselected by using the key attribute's value to call a method on the personBean object. Since the key attribute's value is "personBean.sport", the framework calls the personBean object's getSport method. If the value returned by that method matches one of the option values, that option will be marked as "selected".</p> + +<p>Here is the HTML that results from using the above Struts 2 select tag.</p> + +<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>HTML Created By Struts 2 Select Tag</b></div><div class="codeContent panelContent"> +<script class="theme: Default; brush: html; gutter: false" type="syntaxhighlighter"><![CDATA[ + +<tr> +<td class="tdLabel"> +<label for="save_personBean_sport" class="label">Favorite sport:</label> +</td> +<td> +<select name="personBean.sport" id="save_personBean_sport"> + <option value="football">football</option> + <option value="baseball">baseball</option> + <option value="basketball" selected="selected">basketball</option> +</select> +</td> +</tr> + +]]></script> +</div></div> + +<p>Note the table formatting created by the Struts 2 framework when using the Struts 2 select tag. The CSS classes are defined in style sheets included by the Struts 2 s:head tag. The Struts 2 s:head tag is placed inside the edit.jsp's head section.</p> + +<p>Since the personBean's getSport method returns "baskeball", the basketball option value is marked as selected.</p> + +<h3><a shape="rect" name="Struts2FormTags-Struts2RadioTag"></a>Struts 2 Radio Tag</h3> +<p>The Struts 2 radio tag—like its standard HTML counterpart—is used to display 2 or more choices, only one of which can be selected by the user. Here is the code for the Struts 2 radio button from the example application.</p> + +<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Struts 2 Radio Tag</b></div><div class="codeContent panelContent"> +<script class="theme: Default; brush: html; gutter: false" type="syntaxhighlighter"><![CDATA[ + +<s:radio key="personBean.gender" list="genders" /> + +]]></script> +</div></div> + +<p>Again the key attribute's value determines the value for the label and value attributes. The label's text is derived from the EditAction.properties file (key personBean.gender). Just like the Struts 2 select tag, the list attribute of the Struts 2 radio tag causes the framework to call the getGenders method of the EditAction class. The Array of String objects returned are used to create the individual radio buttons.</p> + +<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>HTML Created By Struts 2 Radio Tag</b></div><div class="codeContent panelContent"> +<script class="theme: Default; brush: html; gutter: false" type="syntaxhighlighter"><![CDATA[ + +<tr> +<td class="tdLabel"> +<label for="save_personBean_gender" class="label">Gender:</label></td> +<td> +<input type="radio" name="personBean.gender" id="save_personBean_gendermale" value="male"/><label for="save_personBean_gendermale">male</label> +<input type="radio" name="personBean.gender" id="save_personBean_genderfemale" value="female"/><label for="save_personBean_genderfemale">female</label> +<input type="radio" name="personBean.gender" id="save_personBean_gendernot sure" checked="checked" value="not sure"/><label for="save_personBean_gendernot sure">not sure</label> +</td> +</tr> + +]]></script> +</div></div> + +<p>Also just like the Struts 2 select tag the result returned by calling the personBean object's getGender method is used to determine which of the radio buttons is checked.</p> + +<h3><a shape="rect" name="Struts2FormTags-Struts2SelectTagObjectBacked"></a>Struts 2 Select Tag - Object Backed</h3> +<p>You may need to create a Struts 2 select tag where the options displayed to the user each have their own value that is different then what is displayed. In the example application, the user's residency is stored as a two-letter abbreviation (e.g. KS), but the form select box should display the full state name (e.g. Kansas). To create such a select box in Struts 2, you would use this code</p> + +<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Struts 2 Select Tag Object Backed</b></div><div class="codeContent panelContent"> +<script class="theme: Default; brush: html; gutter: false" type="syntaxhighlighter"><![CDATA[ + +<s:select key="personBean.residency" list="states" listKey="stateAbbr" listValue="stateName" /> + +]]></script> +</div></div> + +<p>The list value tells the framework to call the getStates method of the EditAction class. That method returns an ArrayList of State objects. Each State object has getStateAbbr and getStateName methods. </p> + +<p>The listKey attribute tells the framework to use the value returned by calling the getStateAbbr method as the value for the value attribute of the HTML option tag and the value returned by calling the getStateName method as the value displayed to the user. So the above Struts 2 select tag code results in this HTML.</p> + +<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>HTML Created By Struts 2 Select Tag</b></div><div class="codeContent panelContent"> +<script class="theme: Default; brush: html; gutter: false" type="syntaxhighlighter"><![CDATA[ + +<tr> +<td class="tdLabel"> +<label for="save_personBean_residency" class="label">State resident:</label></td> +<td> +<select name="personBean.residency" id="save_personBean_residency"> + <option value="AZ">Arizona</option> + <option value="CA">California</option> + <option value="FL">Florida</option> + <option value="KS" selected="selected">Kansas</option> + <option value="NY">New York</option> +</select> +</td> +</tr> + +]]></script> +</div></div> + +<p>The value returned by calling the personBean object's getResidency method determines which of the select tag's option tags is marked as selected. In our example, since getResidency returns "KS", the option tag whose value attribute equals "KS" is marked as selected.</p> + +<h3><a shape="rect" name="Struts2FormTags-Struts2CheckboxTag"></a>Struts 2 Checkbox Tag</h3> +<p>The Struts 2 checkbox tag is used to create the HTML input type equals checkbox tag. The value for the key attribute tells the framework what method to call to determine if the checkbox is checked or not checked. The method called should return a Boolean value (true or false). A return value of true will cause the checkbox to be checked and false the checkbox will not be checked.</p> + +<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Struts 2 Checkbox Tag</b></div><div class="codeContent panelContent"> +<script class="theme: Default; brush: html; gutter: false" type="syntaxhighlighter"><![CDATA[ + +<s:checkbox key="personBean.over21" /> + +]]></script> +</div></div> + +<p>Since the method getOver21 returns true, the checkbox is checked.</p> + +<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>HTML Created By Struts 2 Checkbox Tag</b></div><div class="codeContent panelContent"> +<script class="theme: Default; brush: html; gutter: false" type="syntaxhighlighter"><![CDATA[ + +<tr> +<td valign="top" align="right"> +</td> +<td valign="top" align="left"> +<input type="checkbox" name="personBean.over21" value="true" checked="checked" id="save_personBean_over21"/> +<input type="hidden" id="__checkbox_save_personBean_over21" name="__checkbox_personBean.over21" value="true" /> <label for="save_personBean_over21" class="checkboxLabel">21 or older</label> +</td> +</tr> + +]]></script> +</div></div> + +<p>When the form is submitted and the checkbox is not checked, no value will be posted for the checkbox (this is how HTML forms work). Since the Struts 2 framework will need to update the value of the personBean's over21 instance field to false—given that the check box was not checked—the framework needs a way to determine if the checkbox was not checked after form submission.</p> + +<p>If you examine the HTML code created by the Struts 2 checkbox tag, you'll see that it created a hidden field associated with the personBean.over21 checkbox. When the Struts 2 framework intercepts the submission of this form it will use this hidden form field to check if the associated checkbox field exists in the posted form data. If that checkbox field doesn't exist then the Struts 2 framework will know to update the value of the personBean object's over21 instance variable to false.</p> + +<h3><a shape="rect" name="Struts2FormTags-Struts2checkboxlistTag"></a>Struts 2 checkboxlist Tag</h3> + +<p>The Struts 2 framework provides a unique form field control that creates a series of associated check boxes, one or more of which can be checked. In the example application, the Person class has an Array of Strings, which is used to store car models owned by a person.</p> + +<p>Using the Struts 2 checkbox tag, we can create a series of checkboxes, one for each possible car model the user may own. The value of each String in the personBean's carModels Array will determine which checkboxes are checked.</p> + +<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Struts 2 Checkboxlist Tag</b></div><div class="codeContent panelContent"> +<script class="theme: Default; brush: html; gutter: false" type="syntaxhighlighter"><![CDATA[ + +<s:checkboxlist key="personBean.carModels" list="carModelsAvailable" /> + +]]></script> +</div></div> + +<p>The list attributes value in the checkboxlist tag tells the Struts 2 framework which method to call to get the possible car models. In the example application, the framework will call the EditAction class's getCarModelsAvailable method. That method returns an Array of Strings. For each element of the Array, the Struts 2 framework creates a checkbox (including the associated hidden field described above). </p> + +<p>The key attribute value in the checkboxlist tag tells the Struts 2 framework which method to call on the personBean object to determine which checkboxes should be checked. In the example application, the framework will call the personBean object's getCarModels method. The getCarModels method returns an Array of Strings. For each String value in that Array that matches a String value in the Array returned by the EditAction class's getCarModelsAvailable, the checkbox will be checked.</p> + +<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>HTML Created By Struts 2 Checkboxlist Tag</b></div><div class="codeContent panelContent"> +<script class="theme: Default; brush: html; gutter: false" type="syntaxhighlighter"><![CDATA[ + +<tr> +<td class="tdLabel"> +<label for="save_personBean_carModels" class="label">Car models owned:</label></td> +<td> +<input type="checkbox" name="personBean.carModels" value="Ford" id="personBean.carModels-1" checked="checked"/> +<label for="personBean.carModels-1" class="checkboxLabel">Ford</label> +<input type="checkbox" name="personBean.carModels" value="Chrysler" id="personBean.carModels-2"/> +<label for="personBean.carModels-2" class="checkboxLabel">Chrysler</label> +<input type="checkbox" name="personBean.carModels" value="Toyota" id="personBean.carModels-3"/> +<label for="personBean.carModels-3" class="checkboxLabel">Toyota</label> +<input type="checkbox" name="personBean.carModels" value="Nissan" id="personBean.carModels-4" checked="checked"/> +<label for="personBean.carModels-4" class="checkboxLabel">Nissan</label> +<input type="hidden" id="__multiselect_save_personBean_carModels" name="__multiselect_personBean.carModels" value="" /> +</td> +</tr> + +]]></script> +</div></div> + +<p>Summary<br clear="none"> +There are several other Struts 2 form controls you should explore. If you need more information about the Struts 2 form tags consult the Struts 2 documentation at <a shape="rect" class="external-link" href="http://struts.apache.org">http://struts.apache.org</a>.</p> + +<h3><a shape="rect" name="Struts2FormTags-UpNext"></a>Up Next</h3> + +<p>In our next tutorial we'll cover how to use XML to validate a user's form field entries.</p> + +<div class="table-wrap"> +<table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"> Next </th><td colspan="1" rowspan="1" class="confluenceTd"> Onward to <a shape="rect" href="form-validation-using-xml.html" title="Form Validation Using XML">Form Validation Using XML</a> </td></tr><tr><th colspan="1" rowspan="1" class="confluenceTh"> Prev </th><td colspan="1" rowspan="1" class="confluenceTd"> Return to <a shape="rect" href="debugging-struts.html" title="Debugging Struts">Debugging Struts</a> </td></tr></tbody></table> +</div> +</div> + </div> + + + </div> +</div> +<div class="footer"> + Generated by CXF SiteExporter +</div> +</body> +</html> \ No newline at end of file
Added: websites/production/struts/content/development/2.x/docs/struts-2-maven-archetypes.html ============================================================================== --- websites/production/struts/content/development/2.x/docs/struts-2-maven-archetypes.html (added) +++ websites/production/struts/content/development/2.x/docs/struts-2-maven-archetypes.html Wed Jul 17 09:31:08 2013 @@ -0,0 +1,348 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<html> +<head> + <LINK type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css"> + <style type="text/css"> + .dp-highlighter { + width:95% !important; + } + </style> + <style type="text/css"> + .footer { + background-image: url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif'); + background-repeat: repeat-x; + background-position: left top; + padding-top: 4px; + color: #666; + } + </style> + <link href='http://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' /> + <link href='http://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' /> + <script src='http://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script> + <script src='http://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script> + + <script type="text/javascript"> + SyntaxHighlighter.defaults['toolbar'] = false; + SyntaxHighlighter.all(); + </script> + <script type="text/javascript" language="javascript"> + var hide = null; + var show = null; + var children = null; + + function init() { + /* Search form initialization */ + var form = document.forms['search']; + if (form != null) { + form.elements['domains'].value = location.hostname; + form.elements['sitesearch'].value = location.hostname; + } + + /* Children initialization */ + hide = document.getElementById('hide'); + show = document.getElementById('show'); + children = document.all != null ? + document.all['children'] : + document.getElementById('children'); + if (children != null) { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + } + + function showChildren() { + children.style.display = 'block'; + show.style.display = 'none'; + hide.style.display = 'inline'; + } + + function hideChildren() { + children.style.display = 'none'; + show.style.display = 'inline'; + hide.style.display = 'none'; + } + </script> + <title>Struts 2 Maven Archetypes</title> +</head> +<body onload="init()"> +<table border="0" cellpadding="2" cellspacing="0" width="100%"> + <tr class="topBar"> + <td align="left" valign="middle" class="topBarDiv" align="left" nowrap> + <a href="home.html">Home</a> > <a href="guides.html">Guides</a> > <a href="core-developers-guide.html">Core Developers Guide</a> > <a href="struts-2-maven-archetypes.html">Struts 2 Maven Archetypes</a> + </td> + <td align="right" valign="middle" nowrap> + <form name="search" action="http://www.google.com/search" method="get"> + <input type="hidden" name="ie" value="UTF-8" /> + <input type="hidden" name="oe" value="UTF-8" /> + <input type="hidden" name="domains" value="" /> + <input type="hidden" name="sitesearch" value="" /> + <input type="text" name="q" maxlength="255" value="" /> + <input type="submit" name="btnG" value="Google Search" /> + </form> + </td> + </tr> +</table> + +<div id="PageContent"> + <div class="pageheader" style="padding: 6px 0px 0px 0px;"> + <!-- We'll enable this once we figure out how to access (and save) the logo resource --> + <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"--> + <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div> + <div style="margin: 0px 10px 8px 10px" class="pagetitle">Struts 2 Maven Archetypes</div> + + <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;"> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=108820"> + <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=108820">Edit Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW"> + <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif" + height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a> + <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a> + + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=108820"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add Page"></a> + <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=108820">Add Page</a> + + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=108820"> + <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif" + height="16" width="16" border="0" align="absmiddle" title="Add News"></a> + <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=108820">Add News</a> + </div> + </div> + + <div class="pagecontent"> + <div class="wiki-content"> + <div id="ConfluenceContent"><p>Struts 2 provides several <a shape="rect" class="external-link" href="http://maven.apache.org/">Maven</a> archetypes that create a starting point for our own applications.</p> + +<p><b>Contents</b></p> + +<style type="text/css">/*<![CDATA[*/ +div.rbtoc1334391313780 {margin-left: 0px;padding: 0px;} +div.rbtoc1334391313780 ul {list-style: none;margin-left: 0px;padding-left: 1em;} +div.rbtoc1334391313780 li {margin-left: 0px;padding-left: 0px;} + +/*]]>*/</style><div class="rbtoc1334391313780"> +<ul><li><span class="TOCOutline">1</span> <a shape="rect" href="#Struts2MavenArchetypes-AvailableArchetypes">Available Archetypes</a></li><ul><li><span class="TOCOutline">1.1</span> <a shape="rect" href="#Struts2MavenArchetypes-TheBlankArchetype%28struts2archetypeblank%29">The Blank Archetype (struts2-archetype-blank)</a></li><li><span class="TOCOutline">1.2</span> <a shape="rect" href="#Struts2MavenArchetypes-TheStarterArchetype%28struts2archetypestarter%29">The Starter Archetype (struts2-archetype-starter)</a></li><li><span class="TOCOutline">1.3</span> <a shape="rect" href="#Struts2MavenArchetypes-ThePortletBlankArchetype%28struts2archetypeportlet%29">The Portlet Blank Archetype (struts2-archetype-portlet)</a></li><li><span class="TOCOutline">1.4</span> <a shape="rect" href="#Struts2MavenArchetypes-ThePortletDatabaseArchetype%28struts2archetypedbportlet%29">The Portlet Database Archetype (struts2-archetype-dbportlet)</a></li><li><span class="TOCOutline">1.5</span> <a shape="rect" href="#Struts2MavenArchetypes-TheBlankConventionArchetype%28struts2archetypeconvention%29">The Blank Convention Archetype (struts2-archetype-convention)</a></li><li><span class="TOCOutline">1.6</span> <a shape="rect" href="#Struts2MavenArchetypes-ThePluginArchetype%28struts2archetypeplugin%29">The Plugin Archetype (struts2-archetype-plugin)</a></li></ul><li><span class="TOCOutline">2</span> <a shape="rect" href="#Struts2MavenArchetypes-CreatinganApplicationUsingaMavenArchetype">Creating an Application Using a Maven Archetype</a></li><ul><li><span class="TOCOutline">2.1</span> <a shape="rect" href="#Struts2MavenArchetypes-Stagingrepository">Staging repository</a></li><li><span class="TOCOutline">2.2</span> <a shape="rect" href="#Struts2MavenArchetypes-ArchetypeParameters">Archetype Parameters</a></li></ul><li><span class="TOCOutline">3</span> <a shape="rect" href="#Struts2MavenArchetypes-CommandQuickReference">Command Quick Reference</a></li></ul></div> + +<h2><a shape="rect" name="Struts2MavenArchetypes-AvailableArchetypes"></a>Available Archetypes</h2> + +<h3><a shape="rect" name="Struts2MavenArchetypes-TheBlankArchetype%28struts2archetypeblank%29"></a>The Blank Archetype (struts2-archetype-blank)</h3> + +<p></p><p>The Struts 2 Blank Archetype ("blank-archetype") provides a minimal, but complete, Struts 2 application. It demonstrates some of the most basic Struts 2 concepts.</p> + +<h4><a shape="rect" name="Struts2MavenArchetypes-Features"></a>Features</h4> + +<ul><li>XML-based configuration, demonstrates including additional config file</li><li>Example actions</li><li>Package-level resource bundle</li><li>XML-based validation</li><li>Unit-testing</li></ul> + + +<p>See the <a shape="rect" href="struts-2-blank-archetype.html" title="Struts 2 Blank Archetype">Struts 2 Blank Archetype</a> page for more information, including some basic Maven information, how to build and run the app, and basic application information.</p> + +<h3><a shape="rect" name="Struts2MavenArchetypes-TheStarterArchetype%28struts2archetypestarter%29"></a>The Starter Archetype (struts2-archetype-starter)</h3> + +<p>The Starter archetype creates a more featured application using several common technologies used in production applications.</p> + +<h4><a shape="rect" name="Struts2MavenArchetypes-Features"></a>Features</h4> + +<ul><li>Sitemesh integration</li><li>Action example (instantiated both through Spring and Struts)</li><li>Spring integration</li><li>Validation example (action and action-alias level)</li><li>Conversion example (global and action level)</li><li>Resource bundle (both global, action and package level)</li></ul> + + +<h3><a shape="rect" name="Struts2MavenArchetypes-ThePortletBlankArchetype%28struts2archetypeportlet%29"></a>The Portlet Blank Archetype (struts2-archetype-portlet)</h3> + +<p>The Portlet blank archetype creates a minimally populated JSR 168 portlet.</p> + +<h4><a shape="rect" name="Struts2MavenArchetypes-Features"></a>Features</h4> + +<ul><li>View, Edit, and Help mode examples</li><li>Simple form for preferences in Edit mode</li><li>Can be deployed as a servlet or portlet application</li><li>Can use Maven Jetty plugin to deploy with the pluto-embedded profile (usage 'mvn jetty:run -Ppluto-embedded', then access <a shape="rect" class="external-link" href="http://localhost:8080/" rel="nofollow">http://localhost:8080/</a><artifactId>/pluto/index.jsp)</li></ul> + + +<h3><a shape="rect" name="Struts2MavenArchetypes-ThePortletDatabaseArchetype%28struts2archetypedbportlet%29"></a>The Portlet Database Archetype (struts2-archetype-dbportlet)</h3> + +<p>The Portlet database archetype creates a simple JSR 168 portlet that displays the contents of a database table.</p> + +<h4><a shape="rect" name="Struts2MavenArchetypes-Features"></a>Features</h4> + +<ul><li>Uses Spring and Hsql to show a real database query</li><li>Builtin caching of query results</li><li>View, Edit, and Help mode examples</li><li>Simple form for preferences in Edit mode</li><li>Can be deployed as a servlet or portlet application</li><li>Can use Maven Jetty plugin to deploy as a servlet webapp</li></ul> + + +<h3><a shape="rect" name="Struts2MavenArchetypes-TheBlankConventionArchetype%28struts2archetypeconvention%29"></a>The Blank Convention Archetype (struts2-archetype-convention)</h3> + +<h4><a shape="rect" name="Struts2MavenArchetypes-Features"></a>Features</h4> + +<ul><li>Convention-based validation</li><li>Example actions</li><li>Package-level resource bundle</li><li>Unit-testing</li><li>Google AppEgine aware</li></ul> + + +<h3><a shape="rect" name="Struts2MavenArchetypes-ThePluginArchetype%28struts2archetypeplugin%29"></a>The Plugin Archetype (struts2-archetype-plugin)</h3> + +<h4><a shape="rect" name="Struts2MavenArchetypes-Features"></a>Features</h4> + +<ul><li>Example new result type</li><li>Example XML-based configuration</li></ul> + + +<h2><a shape="rect" name="Struts2MavenArchetypes-CreatinganApplicationUsingaMavenArchetype"></a>Creating an Application Using a Maven Archetype</h2> + +<p>Run the following command from your new project's parent directory. The project will be created in a sub-directory named after the <tt>artifactId</tt> parameter.</p> + +<p>The first two parameters, <tt>groupId</tt> and <tt>artifactId</tt>, should be set according to your needs:</p> + +<ul><li><tt>groupId</tt><br clear="none"> + This should be the root package of your application, e.g., com.mycompany.myapp. </li><li><tt>artifactId</tt><br clear="none"> + Names the project directory that will be created in the current directory.</li></ul> + + +<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ +mvn archetype:generate -B \ + -DgroupId=tutorial \ + -DartifactId=tutorial \ + -DarchetypeGroupId=org.apache.struts \ + -DarchetypeArtifactId=struts2-archetype-blank \ + -DarchetypeVersion=<version> +]]></script> +</div></div> + +<p>where <version> is archetype's version you want to use, eg. 2.2.1</p> + +<h3><a shape="rect" name="Struts2MavenArchetypes-Stagingrepository"></a>Staging repository</h3> +<p>If the above command will fail because of missing archetypes in central repository, you can try to use staging repository like below</p> +<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ +mvn archetype:generate -DarchetypeCatalog=https://repository.apache.org/content/repositories/snapshots/ +]]></script> +</div></div> + +<p>or this</p> + +<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ +mvn archetype:generate -DarchetypeCatalog=http://struts.apache.org/ +]]></script> +</div></div> + +<h3><a shape="rect" name="Struts2MavenArchetypes-ArchetypeParameters"></a>Archetype Parameters</h3> + +<p>The <tt>-B</tt> option runs <tt>archetype:generate</tt> in batch mode; it avoids a prompt to confirm our settings.</p> + +<div class="table-wrap"> +<table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"> Parameter </th><th colspan="1" rowspan="1" class="confluenceTh"> Description </th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>groupId</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> The id for the group the application belongs to. Usually is the root package for applications in your company, e.g. com.mycompany </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>artifactId</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> The id for the project. The project will be created a sub-directory named after this parameter. </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>archetypeGroupId</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> The group id of the archetype. Will always be <tt>org.apache.struts</tt> for Struts archetypes </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>archetypeArtifact Id</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> The id of the archetype </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>archetypeVersion</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> The version of the archetype </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>package</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> (Optional) The base Java package to use for generated source code. Defaults to <tt>archetypeGroupId</tt> if not specified. </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>remoteRepositories</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> (Optional) A list of remote repositories that contain the archetype. </td></tr></tbody></table> +</div> + + +<h2><a shape="rect" name="Struts2MavenArchetypes-CommandQuickReference"></a>Command Quick Reference</h2> + +<p>These commands are used from the directory created by the archetype plugin (the project's sub-directory that was created in the previous step).</p> + +<ul><li>To build</li></ul> + + +<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ + mvn install +]]></script> +</div></div> + +<ul><li>To create IntelliJ IDEA project files</li></ul> + + +<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ + mvn idea:idea +]]></script> +</div></div> + +<ul><li>To create Eclipse project files</li></ul> + + +<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ + mvn eclipse:eclipse -Dwtpversion=1.5 +]]></script> +</div></div> + +<ul><li>To run test cases</li></ul> + + +<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ + mvn test +]]></script> +</div></div> + +<ul><li>To clean up (removes generated artifacts)</li></ul> + + +<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ + mvn clean +]]></script> +</div></div> + +<ul><li>To package (creates a WAR file)</li></ul> + + +<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ + mvn package +]]></script> +</div></div> + +<ul><li>To grab necessary JAR files etc.</li></ul> + + +<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ + mvn initialize +]]></script> +</div></div> + +<ul><li>To run it with Jetty</li></ul> + + +<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ + mvn jetty:run +]]></script> +</div></div></div> + </div> + + <div class="tabletitle"> + Children + <span class="smalltext" id="show" style="display: inline;"> + <a href="javascript:showChildren()">Show Children</a></span> + <span class="smalltext" id="hide" style="display: none;"> + <a href="javascript:hideChildren()">Hide Children</a></span> + </div> + <div class="greybox" id="children" style="display: none;"> + $page.link($child) + <span class="smalltext">(Apache Struts 2 Documentation)</span> + <br> + </div> + + </div> +</div> +<div class="footer"> + Generated by CXF SiteExporter +</div> +</body> +</html> \ No newline at end of file Added: websites/production/struts/content/development/2.x/docs/struts-2-portlet-tutorial.data/AddBookmarkForm.jpg ============================================================================== Binary file - no diff available. Propchange: websites/production/struts/content/development/2.x/docs/struts-2-portlet-tutorial.data/AddBookmarkForm.jpg ------------------------------------------------------------------------------ svn:mime-type = image/jpeg Added: websites/production/struts/content/development/2.x/docs/struts-2-portlet-tutorial.data/ListBookmarks.GIF ============================================================================== Binary file - no diff available. Propchange: websites/production/struts/content/development/2.x/docs/struts-2-portlet-tutorial.data/ListBookmarks.GIF ------------------------------------------------------------------------------ svn:mime-type = image/gif Added: websites/production/struts/content/development/2.x/docs/struts-2-portlet-tutorial.data/ListBookmarks.jpg ============================================================================== Binary file - no diff available. Propchange: websites/production/struts/content/development/2.x/docs/struts-2-portlet-tutorial.data/ListBookmarks.jpg ------------------------------------------------------------------------------ svn:mime-type = image/jpeg Added: websites/production/struts/content/development/2.x/docs/struts-2-portlet-tutorial.data/ListBookmarksInEditMode.jpg ============================================================================== Binary file - no diff available. Propchange: websites/production/struts/content/development/2.x/docs/struts-2-portlet-tutorial.data/ListBookmarksInEditMode.jpg ------------------------------------------------------------------------------ svn:mime-type = image/jpeg Added: websites/production/struts/content/development/2.x/docs/struts-2-portlet-tutorial.data/bookmark-portlet.zip ============================================================================== Binary file - no diff available. Propchange: websites/production/struts/content/development/2.x/docs/struts-2-portlet-tutorial.data/bookmark-portlet.zip ------------------------------------------------------------------------------ svn:mime-type = application/zip
