[ http://issues.apache.org/struts/browse/STR-632?page=all ]
Don Brown resolved STR-632:
---------------------------
Resolution: Won't Fix
This is just way too old. Feel free to open if you have a new patch.
> Some more Struts docs
> ---------------------
>
> Key: STR-632
> URL: http://issues.apache.org/struts/browse/STR-632
> Project: Struts Action 1
> Type: Improvement
> Components: Core
> Versions: Nightly Build
> Environment: Operating System: other
> Platform: Other
> Reporter: Vic Cekvenich
> Assignee: Ted Husted
> Priority: Minor
> Attachments: newbie.xml
>
> <section href="StrutsRight" name="How do I know I am doing Struts right?">
> <p>
> Struts is an MVC implementation. The key is to call the action first and not
> call the JSP ever.<br/>
> If you call the action, and it returns the JSP, you are doing MVC!.<br/>
> If you link to the JSP, you are not doing MVC.<br/>
> The action has a chance to pre populate the form bean, or on a submit validate
> or to dispatch to another action.<br/>
> You would define additional actions in action-mappings in
> Struts-config.xml.<br/>
> </p>
> </section>
> <section href="QuickValidator" name="Is there a quick overview for Validator
> set
> up?">
> <p>
> Make sure you have commons-validator.jar in lib.<br/>
> Make sure you have Jakarta-oro.jar in lib. This is the regular expression
> library.<br/>
> <br/>
> Add this to struts-config.
> <br/>
> <;!-- Validator --> <br/>
> <message-resources<br/>
> parameter="ApplicationResources"/><br/>
> <br/>
> <!-- Validator --><br/>
> <!-- Add multiple validator resource files by setting the pathname
> property --><br/>
> <plug-in className="org.apache.struts.validator.ValidatorPlugIn"><br/>
> <set-property property="pathnames"
> value="/WEB-INF/config/validator-rules.xml,<br/>
>
> /WEB-INF/config/validation.xml"/><br/>
> </plug-in><br/>
> <br/>
> <br/>
> ApplicationResources will contain your messages.<br/>
> Validatior-Rules.xml contains validation rules.<br/>
> Validaton.xml contains a list of forms and the fields to validate.<br/>
> <br/>
> Example Validation.xml:<br/>
> <br/>
> <form-validation><br/>
> <form name="nameZoomForm"><br/>
> <field<br/>
> property="fstName"<br/>
> depends="required,mask"><br/>
> <arg0 key="name.firstname.displayname"/><br/>
> <var><br/>
> <var-name>mask</var-name><br/>
> <var-value>^\w+$</var-value><br/>
> </var><br/>
> </field><br/>
> <field<br/>
> property="lastName"<br/>
> depends="required,mask"><br/>
> <msg<br/>
> name="mask"<br/>
> key="name.Last"/><br/>
> <arg0 key="name.lastname.displayname"/><br/>
> <var><br/>
> <var-name>mask</var-name><br/>
> <var-value>^<a-zA-Z]*$</var-value><br/>
> </var><br/>
> </field><br/>
> </form><br/>
> </formset><br/>
> </form-validation><br/>
> <br/>
> This will use message Application Resource properties to construct the
> message.<br/>
> <br/>
> Make your form bean extend ValidatorForm:<br/>
> <br/>
> import org.apache.struts.action.ActionErrors;<br/>
> import org.apache.struts.validator.ValidatorForm;<br/>
> <br/>
> public class MyFrmBean extends ValidatorForm {<br/>
> // ValidatorForm base implements validate method.<br/>
> <br/>
> And now to use it. Note that action mapping of validate=true will turn on
> automatic validation.<br/>
> To manually invoke a validation in your action code something like this:<br/>
> public ActionForward execute(<br/>
> ActionMapping mapping,<br/>
> ActionForm form,<br/>
> HttpServletRequest request,<br/>
> HttpServletResponse response) {<br/>
> <br/>
> // assume we are dispatched to a submitted save<br/>
> <br/>
> // cast the Struts returned form bean<br/>
> <br/>
> MyBean frm = (MyBean) form;<br/>
> //ask for the validation<br/>
> ActionErrors errors = frm.validate(mapping,request);<br/>
>
> if (errors != null andAnd !errors.empty() ) { <br/>
> //if there are errors save<br/>
> saveErrors(request, errors);<br/>
> return (mapping.findForward("display"));<br/>
> } <br/>
> // frm.save();<br/>
> <br/>
> return (mapping.findForward("forward"));<br/>
> } <br/>
> <br/>
> In your JSP page have this:<br/>
> <br/>
> <html:errors/><br/>
> <br/>
> <logic:messagesPresent><br/>
> <bean:message key="errors.header"/><br/>
> <ul><br/>
> <html:messages id="error"><br/>
> <li><bean:write name="error"/></li><br/>
> </html:messages><br/>
> </ul><hr><br/>
> </logic:messagesPresent><br/>
> <br/><br/>
> Above will display the error saved.<br/>
> <br/>
> To do a client side validation add this tag to your JSP page<br/>
> <html:javascript formName="formName" /><br/>
> </p>
> </section>
> <section href="QuickTiles" name="Is there a quick overview for Tiles set up?">
> <p>
> <br/>
> Make sure you have tiles.jar in lib.<br/>
> <br/>
> Change web.xml to:<br/>
> <web-app><br/>
> <servlet><br/>
> <servlet-name>action</servlet-name><br/>
>
> <servlet-class>org.apache.struts.tiles.ActionComponentServlet</servlet-class><br/>
> <init-param><br/>
> <param-name>definitions-config</param-name><br/>
> <param-value>/WEB-INF/config/tiles-defs.xml</param-value><br/>
> <br/>
> <br/>
> And add this to Struts-config.xml:<br/>
> <br/>
> <controller<br/>
> processorClass="org.apache.struts.tiles.TilesRequestProcessor"/><br/>
> <br/>
> And create a tiles-defs like this:<br/>
> <tiles-definitions><br/>
> <definition name="firstDef" template="/pages/common/simpleLay.jsp"><br/>
> <put name='header' content='/pages/common/header.jsp' /><br/>
> <put name='footer' content='/pages/common/footer.jsp' /><br/>
> <put name='leftBar' content='/pages/common/leftBar.jsp' /><br/>
> <put name='title' content=' Title '/><br/>
> <put name='body' content='/pages/WelcomePg.jsp'/><br/>
> </definition><br/>
> <definition name="nextDef" extends="firstDef"><br/>
> <put name='title' content='Name'/><br/>
>
> <put name='body' content='/pages/SrchPg.jsp'/><br/>
> </definition><br/>
> <br/>
> The most important setting here is the template of the layout.<br/>
> Here is what simpleLay.jsp might look like:<br/>
> <br/>
> <%@ taglib uri="/WEB-INF/tiles.tld" prefix="tiles" %><br/>
> <html><br/>
> <head><br/>
> <title><tiles:getAsString name="title"/></title><br/>
> </head><br/>
> <body><br/>
> <div ><br/>
> <TABLE width="100%"><br/>
> <TR><br/>
> <TD colspan="2"><tiles:insert attribute="header"
> /></TD></TR><br/>
> <TR ><br/>
> <TD width="160" valign="top"><tiles:insert attribute="leftBar"
> /></TD><br/>
> <TD><tiles:insert attribute="body" /></TD></TR><br/>
> <TR><br/>
> <TD colspan="2"><tiles:insert attribute="footer" /></TD><br/>
> </TR><br/>
> </TABLE><br/>
> </body><br/>
> </html><br/>
> <br/>
> See how easy it was to create a layout?<br/>
> <br/>
> And the definition in tiles-config.xml specifices which "tiles" to insert
> where.<br/>
> The next definition basically says it is the same as the first one except it
> has
> a different main body page.<br/>
> And the last part, in your action mappings, instead of forwarding to JSP,
> forward to your definitoin name, like this:<br/>
> <forward<br/>
> name="display"<br/>
> path="nextDef"/><br/>
> </action><br/>
> </p>
> </section>
> <section href="WhenHowStrutsFormBeans" name="When must I use the Struts Form
> Beans vs. other Beans?">
> <p>
> If you are submitting, updating or inserting!<br/>
> If you are just displaying data for read only, you can use <display:tag> or
> JSTL or even JSP bean define. (Note: JSTL will replace the bean and logic tags
> but not the HTML tags)<br/>
> It is a good idea to still populate those beans in the action, and not do that
> in the JSP, and save it in the request (or maybe session if you will need it
> in
> the entire app. Make sure you kill session beans when they are not
> needed).<br/>
> If you are doing read only beans as above, you do not need to define a form
> bean
> in the action mapping.<br/>
> <br/>
> When you are updating you will typically need to define the form bean in the
> action mapping, and then you must extend a Struts Form Bean such as
> ValidatorForm.<br/>
> Struts will auto-magically pass this form bean in the execute method.<br/>
> public ActionForward execute(<br/>
> ActionMapping mapping,<br/>
> ActionForm form,<br/>
> HttpServletRequest request,<br/>
> HttpServletResponse response) {<br/>
> // and you can get a handle to it like so.<br/>
> MyBean frm = (MyBean) form;<br/>
> Now you could do things to it, such as<br/>
> frm.populate(long_id);<br/>
> or<br/>
> frm.populate(new PassedJavaBean(long_id));<br/>
> <br/>
> This update-able bean is used with the HTML page tag.<br/>
> The setters for the properties for this bean are fired before the execute
> method.<br/>
> This is why it is a good idea that the bean always returns and takes String
> arguments in its getters and setters, since HTTP is a String protocol.<br/>
> Internally, the Form Bean getters and setters can be implemented using native
> data types like BigDecimmal and SQL.Date.<br/>
> Sometimes the getters do formatting of strings, and dates.<br/>
> </p>
> </section>
> <section href="SinglePageMasterDetial" name="How do I do an updateable master
> detail on a single page?">
> <p>
> For example, let's say you have an invoice and line items. Struts will iterate
> all the setters for your Since there are 2 entities here, a single of one and
> multiple of another, you coul have 2 beans. You can implement iterator
> interface
> in your form beans. So in this case the "invoice" bean contains a "line_items"
> bean. The line_items bean would iterate on the page usig a logic iterate tag.
> </p>
> </section>
> <section href="ActionMessages" name="How do I pass and receive messages in the
> action?">
> <p>
> One way is:<br/>
> MyMsgBean msg = (MyMsgBean) request.getAttribute("MsgBeanName");<br/>
> This assumes you set a message in request, in another action.<br/>
> Same works for session.<br/>
> And yet another is:<br/>
> String pk = request.getParameter("pk");<br/>
> This assumes you are passing in a link page tag with the parm of the primary
> key
> the users clicked on.<br/>
> <br/>
> Another is:<br/>
> String parm = request.getParameter("dispatch");<br/>
> This assume you set a parm in the page submit tag.<br/>
> This can be used to call different methods to handle SaveExecute or
> InsertExecute.<br/>
> </p>
> </section>
> <section href="JAAS" name="How do I redirect a user to a login page if the
> user
> is not logged in?">
> <p>
> <br/>
> The web container does this for you, using JAAS. It is best to start with that
> and then extend using getUserPrincipal().<br/>
> </p>
> </section>
> <section href="SturtsMenu" name="How Do I integrate the Struts-Menu?">
> <p>
> <br/>
> One commonly needed component for a web applications is a centralized menu or
> centralized navigation. Without this, you would put code for navigation all
> over
> the place in many JSP pages. A typically use is to create a tile using Struts
> Tiles and place a menu tag on it.<br/>
> The menu tag then emits JavaScript to the browser.<br/>
> See:<br/>
> http://www.dhtmlcentral.com/projects/coolmenus<br/>
> <br/>
> You can get Struts Menu http://sourceforge.net/projects/struts-menu .<br/>
> <br/>
> To install Struts Menu modify your Sruts-Config.XML to add the
> Struts-menu.<br/>
> <br/>
> <plug-in<br/>
> className="com.fgm.web.menu.MenuPlugIn"><br/>
> <set-property<br/>
> property="menuConfig"<br/>
> value="/WEB-INF/config/menu-config.xml"/><br/>
> </plug-in><br/>
> <br/>
> Also place the Struts-menu.jar in the Lib folder and modify web.xml to add the
> Strruts Menu tag, like so.<br/>
> <taglib><br/>
> <taglib-uri>/WEB-INF/menu.tld</taglib-uri><br/>
> <taglib-location>/WEB-INF/lib/struts-menu.tld</taglib-location><br/>
> </taglib><br/>
> <br/>
> This will enable the menus.<br/>
> <br/>
> You can look at the documentation and the sample WAR that ships with
> Struts-menu
> that demonstrates possible displays of the menu.<br/>
> The simple displayer is called "Simple".<br/>
> <br/>
> You place a menu tag on a tile like this:<br/>
> <menu:useMenuDisplayer name="Simple"><br/>
> <table cellpadding=2 cellspacing=2><br/>
> <tr><td><br/>
> <menu:displayMenu name="MenuToDisplay"/><br/>
> </td></tr><br/>
> </table><br/>
> </menu:useMenuDisplayer><br/>
> <br/>
> This will display the named menu.<br/>
> How you need to setup up the choices to display. You do this it the
> menu-config.xml.<br/>
> <br/>
> <MenuConfig><br/>
> <Displayers><br/>
> <Displayer name="DropDown"<br/>
> type="com.fgm.web.menu.displayer.DropDownMenuDisplayer"/><br/>
> <Displayer name="Simple"<br/>
> type="com.fgm.web.menu.displayer.SimpleMenuDisplayer"/><br/>
> </Displayers><br/>
> <Menus><br/>
> <Menu name="MenuNameToDisplay" title=""><br/>
> <Item name="NamSrch" title="Item Search"<br/>
> location="srchMsg"/><br/>
> <Item name="ItemSrch" title="Item Search"<br/>
> location="srchItem"/><br/>
> </Menu><br/>
> </Menus><br/>
> </MenuConfig><br/>
> <br/>
> The Item Name is the name of menu item, and it not used in simple cases.<br/>
> The Tile is what will be displayed on the menu.<br/>
> The location is the path of the action mapping to be invoked.<br/>
> <br/>
> And here is a more complicated example.<br/>
> It is possible to create drop down menus using Struts-menu.<br/>
> <br/>
> <MenuConfig><br/>
> <Displayers><br/>
> <Displayer name="DropDown"<br/>
> type="com.fgm.web.menu.displayer.DropDownMenuDisplayer"/><br/>
> <Displayer name="Simple"<br/>
> type="com.fgm.web.menu.displayer.SimpleMenuDisplayer"/><br/>
> <Displayer name="CoolMenu"<br/>
> type="com.fgm.web.menu.displayer.CoolMenuDisplayer"/><br/>
> </Displayers><br/>
> <Menus><br/>
> <Menu name="Main" title="Main" ><br/>
> <Item name="MainPg" title="Main" location="mainPg.jsp"/><br/>
> <Item name="WhyMVC" title="Why MVC" location="whyMVC.jsp"/><br/>
> <Item name="Downloads" title="Downloads" location="downloads.jsp"/><br/>
> </Menu><br/>
> <Menu name="Support" title="Support" ><br/>
> <Item name="DBRelated" title="DB Related" location="dbRelated.jsp"/><br/>
> <Item name="JSP Tags" title="JSP Tags" location="jspTags.jsp"/><br/>
> <Item name="Unix" title="Unix" location="unix.jsp"/><br/>
> <Item name="SOAP" title="SOAP" location="soap.jsp"/><br/>
> <Item name="SupportPg" title="Support" location="support.jsp"/><br/>
> <Item name="Recommendations" title="Recommendations"
> location="recommendations.jsp"/><br/>
> </Menu><br/>
> <br/>
> In above case we have 2 drop down menus we want to display side by side.
> Typically you might have 4 across to display.<br/>
> <br/>
> You would then use a tag like this:<br/>
> <script language="JavaScript1.2" src="../scripts/coolmenus4.js"><br/>
> </script><br/>
> <script src="../scripts/coolmenu-config.js"><br/>
> </script><br/>
> <menu:useMenuDisplayer name="CoolMenu"
> bundle="org.apache.struts.action.MESSAGE"><br/>
> <menu:displayMenu name="Main"/><br/>
> <menu:displayMenu name="Support"/><br/>
> </menu:useMenuDisplayer><br/>
> <br/>
> This will emit JavaScript from your menu tag.<br/>
> To set up colors and other settings you would need to edit the coolmenus4.js
> configuration file, in this case places in the scripts folder in your web
> app.<br/>
> For example:<br/>
> oCMenu.barcolor="#666666" //The color of the background bar - Value:
> "color"<br/>
> oCMenu.fromtop=0 //This is the left position of the menu. (Only in use if
> menuplacement below is 0 or aligned) (will change to adapt any borders) -
> Value:
> px || "%"<br/>
> <br/>
> In the future version, Stuts-menu might allow you to invoke the action's
> cleanup
> method before going to another action by invoking the action in the paths
> executeCleanUp method.<br/>
> <br/>
> The Struts-menu was contributed by ssayles at users.sourceforge.net.<br/>
> It currently uses CoolMenu but could be configured for any menu. CoolMenu was
> developed by [EMAIL PROTECTED] .<br/>
> </p>
> </section>
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/struts/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]