Apress Pro Apache Struts with Ajax phần 10 pptx

48 206 0
Apress Pro Apache Struts with Ajax phần 10 pptx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

APPENDIX B ■ STRUTS DEVELOPMENT TOOLS 455 Figure B-16. Refactoring code with UML Figure B-17. Previewing your JavaDoc with no lengthy generation process AppB_7389_CMP2 9/25/06 9:15 PM Page 455 Action Designer As with WebSphere, JBuilder includes a diagram-based designer for you to build your Struts applications (see Figure B-18). Using the Action Designer, you can create actions, set up Action Forwards, configure exception handling, and view pages, all in a simple diagram. In the back- ground, JBuilder will generate the code for each of the pieces, creating Java code for the actions and JSP pages for the view, and updating the Struts configuration as appropriate. Figure B-18. Struts application modeling in JBuilder As with most of the other designers, we have found that building a project like this can quickly get messy, but this kind of view does serve as a great way to verify that the code you have written is connected as you expected. JBuilder Summary Overall, JBuilder is a strong IDE; it has excellent support for JSP editing and some good UML tools. We really miss the refactoring support when using this IDE, but not everyone will. The Struts support is excellent; it is certainly not something Borland bolted on as an afterthought. What we like about JBuilder and Borland is that they now have the whole suite of tools available, and they integrated everything very well. So, in large projects you can have your IDE, issue tracking, source control, and change control all integrated together. APPENDIX B ■ STRUTS DEVELOPMENT TOOLS456 AppB_7389_CMP2 9/25/06 9:15 PM Page 456 The main drawback we found with JBuilder is that it is a mammoth to run. We are run- ning on 1.5GB of RAM, so for us it is not so bad, but we used it on a friend’s machine once with just 512MB RAM, and it was ridiculously slow. We have noticed that the memory usage will slowly creep up through a session, so you may find yourself stopping and starting the IDE once or twice a day on slow machines. JBuilder is definitely worth a try; you might even feel that this is the IDE for you. We have certainly found that people love or hate JBuilder in equal measure just as people love or hate Eclipse/WebSphere. We know a lot of developers who use JBuilder X or JBuilder 2006 and love it. JBuilder Next Step Go get a copy! You can download a 30-day trial of the Enterprise Edition from http://www. borland.com, and it is also giving away the Foundation Edition for JBuilder 2006, although that doesn’t have support for Struts. Borland has an active, developer-focused web site at http://bdn.borland.com, where you will find a mass of information about all its products. Struts Console Struts Console is a tool developed by James Holmes that provides a Swing-based editor for the majority of the Struts configuration files. You can use Struts Console either as a stand-alone or as a plug-in to one of the following IDEs: •Eclipse • IBM WebSphere •IntelliJ IDEA •NetBeans •Sun ONE Studio •Borland JBuilder •Oracle JDeveloper We prefer to use it within Eclipse, since that is the IDE that we use for most of our devel- opment. Getting Started To get started with Struts Console, you need to download the current distribution from James Holmes’ web site at http://www.jamesholmes.com/struts/console/index.html. As of the time of writing, the current version of Struts Console was 4.8. We are only going to discuss setting up Struts Console in an Eclipse environment; you will find instructions for running Struts Console stand-alone or in one of the other IDEs on James Holmes’ web site. So once you have Struts Console downloaded, you need to shut down your copy of Eclipse if it isn’t already closed and open up the directory where you installed Eclipse. APPENDIX B ■ STRUTS DEVELOPMENT TOOLS 457 AppB_7389_CMP2 9/25/06 9:15 PM Page 457 In this directory you will find another directory called plugins. Copy the com.jamesholmes. console.struts directory from the Struts Console directory into the plugins directory in your Eclipse installation directory, and then restart Eclipse. To verify that the Struts Console plug-in has been correctly installed, open the Preferences dialog box from the Window menu and you should see Struts Console listed on the left side, as shown in Figure B-19. Figure B-19. Struts Console installed in Eclipse With that done, you can now start using Struts Console to edit the Struts configuration files. Editing the Struts Configuration File The file we want to look at editing with Struts Console is struts-config.xml. To open the struts-config.xml file in Struts Console, locate it in the Navigator, right-click it, and choose Open With ➤ Struts Console. Struts Console will now open up, and the sections of the struts- config.xml file will be listed on the left side (see Figure B-20). If Struts Console reports that the file doesn’t match the Struts DTD but your application still runs, then you may have some of the elements in the wrong order. At one point, we had the <global-exceptions> tag after the <global-forwards> tag, but the DTD defines that they should appear the other way around. Struts Console will enforce strict adherence to the DTD. Figure B-20. Struts Console configuration editor APPENDIX B ■ STRUTS DEVELOPMENT TOOLS458 AppB_7389_CMP2 9/25/06 9:15 PM Page 458 To start with, try editing the configuration of one of your form beans. Notice that we have used the JavaEdge application for our examples. To open up the configuration screen for your form bean, collapse the Form Beans node in the left-hand tree view, and you will see a list of all the defined form beans. Select the form bean you want to edit, and the details for the bean will appear in the right-hand pane (see Figure B-21). Figure B-21. Manipulating form bean configuration with Struts Console In addition to specifying a name and type for your form bean, you are able to specify a dif- ferent configuration bean to use when reading in the configuration details for this form bean. In the Type drop-down box, you will find that the three types of DynaActionForm are listed already; using the Form Properties tab at the bottom, you can build up a dynamic action form. The last tab, Referencing Actions, shows a list of all action mappings that use this particular form bean. Now take at look at the configuration for one of your actions. Collapse the Action Mappings node in the tree and select the action you want to configure, as shown in Figure B-22. Figure B-22. Setting up action mappings with Struts Console APPENDIX B ■ STRUTS DEVELOPMENT TOOLS 459 AppB_7389_CMP2 9/25/06 9:15 PM Page 459 APPENDIX B ■ STRUTS DEVELOPMENT TOOLS460 As with the form bean configuration, you are able to specify the name of the action as well as a configuration bean to change the way in which the configuration is processed by Struts. You have three options for what the action is mapped to: You can choose an Action class, you can choose to forward to a resource, or you can choose to include a resource in the response stream. These three choices are mutually exclusive. Under the Form Bean tab at the bottom of the screen, you configure, if required, the form bean used for this action. Under the Exceptions tab, you can configure specific exception han- dling for this action. The Forwards tab allows you to configure Action Forwards that are specific to this action. The final tab, Properties, allows you to specify additional configuration parame- ters that you can use in conjunction with any custom configuration beans. The last section of the struts-config.xml file that we want to look at in detail with Struts Console is the controller configuration (see Figure B-23). Using this section, you can configure which controller class to use, such as RequestProcessor or TilesRequestProcessor, as well as specify the behavior for file uploads and content types other than text/html. Figure B-23. Configure the Struts controller with Struts Console We’re sure you noticed many more configuration options as you browsed the Struts Console interface. Many of these are explained in detail in Chapters 2 and 3. You will find full details of those parameters not found in this book on the Struts web site. Of course, these are not the only sections of the struts-config.xml file you can edit using Struts Console. The remaining nodes of the tree view will allow you to configure global exceptions and global forwards as well as data sources, message resources, and plug-ins. Editing Other Configuration Files Struts Console has support for editing more than just the struts-config.xml file—it also sup- ports the Tiles and Validator configuration files as well. Not only that, but you can also edit any tag library descriptor file. Struts Console Summary What can we say about Struts Console other than it is cool? This is one of those utilities you should just have. It is small, lightweight, and free. Struts Console allows you to edit all the pos- sible parameters for Struts you could ever think of and few you didn’t know existed. The XML it generates adheres 100 percent to the Struts DTD, so there will be no problems having Struts AppB_7389_CMP2 9/25/06 9:15 PM Page 460 APPENDIX B ■ STRUTS DEVELOPMENT TOOLS 461 load it into the servlet container. There are no real downsides to this tool—we encourage you to go and get it as soon as you finish reading this book. Struts Console Next Step We’re sure you can see that Struts Console is a useful tool that can take a lot of the drudge work out of configuring your Struts application. It is really very simple to use, especially if you are already familiar with the Struts framework, which by getting this far into the book we’ll assume you are. Exadel Studio Exadel Studio is a full Struts development tool from Exadel, Inc. (http://www.exadel.com/web/ portal/home). It comes in two versions: either as a plug-in for Eclipse or as a stand-alone ver- sion. There is no real difference between the two, since the stand-alone version is just the basic Eclipse distribution and the plug-in packaged together. The whole idea behind Exadel Studio is that you have a full environment in which to develop your Struts-based applications. To this end, Exadel Studio comes with a massive num- ber of features that aren’t directly related to Struts but will make your development life easier. If you want to try out Exadel Studio, you can download a 30-day trial from the Exadel web site. For this book, we used Exadel Studio 4.0. Struts Projects Exadel Studio adds a new project type to Eclipse, the Struts project, which you must use in order to take advantage of most of the features. When you start a Struts project, you get the base files you need such as struts-config.xml and web.xml. Configuration File Editors As with most of the tools discussed here, Exadel Studio provides an editor for the struts-config. xml file, but chooses to use a different approach. In Exadel Studio, the struts-config.xml file node in the project tree is collapsible and shows all the subsections of the files (see Figure B-24). Each section of the file can be collapsed further to show the composite parts. Figure B-24. Exadel Studio configuration navigator AppB_7389_CMP2 9/25/06 9:15 PM Page 461 Selecting one of the nodes highlights the detail for that node in the Properties window, where you can edit them directly (see Figure B-25). Figure B-25. Configuration properties view in Exadel Studio If you right-click a node, you get the options for that particular node, allowing you to view the properties in a separate, more organized dialog box or to perform configuration actions specific to that node. For instance, if you right-click the action-mappings node, you can choose to add a new action. This will bring up an action mapping wizard, as shown in Figure B-26. Figure B-26. Adding a new action with Exadel Studio APPENDIX B ■ STRUTS DEVELOPMENT TOOLS462 AppB_7389_CMP2 9/25/06 9:15 PM Page 462 If the Action class doesn’t already exist, you can enter the name of a new class that will be created later on. While Exadel Studio won’t automatically create a new Action class for an action mapping, you can right-click the action mapping and choose Generate to create the Action class. Once the action mapping is created, you can then right-click and add forwards, exceptions, and properties. This behavior is carried out through the entire configuration file editor. Along with support for the struts-config.xml file, the Professional Edition of Exadel Studio includes editors for Tiles framework configuration, Validator configuration, and TLD files. Exadel Studio also comes with an editor for the web.xml file that works in a similar way to the struts-config.xml editor (see Figure B-27). Figure B-27. Editing web.xml with Exadel Studio One last point on the Exadel Studio configuration file support in the Professional Edition is that it has fully integrated support for Struts modules. With more and more applications using multiple modules in their implementation, this is an important feature for any Struts tool. XML Editor For those times when an editor is not available or when you want to get down and dirty with the configuration, Exadel Studio provides a simple XML editor with support for code high- lighting and basic code completion. Eclipse developers will find this quite useful due to the lack of an XML editor out of the box with Eclipse. JSP Editor Another thing that is sadly lacking in Eclipse is a good JSP editor. Exadel Studio includes quite a good editor that has customizable code highlighting and good support for code completion, APPENDIX B ■ STRUTS DEVELOPMENT TOOLS 463 AppB_7389_CMP2 9/25/06 9:15 PM Page 463 as shown in Figure B-28. A useful feature of the code completion is that it is not just limited to HTML but also reads the TLD for any tag libraries specified in your JSP file and provides code completion for those as well. Figure B-28. Excellent JSP editing support in Exadel Studio On top of this, Exadel Studio includes what has got to be one of our favorite features available: JSP Preview. If you are like us, then you will hate having to tune designs by making a change and then redeploying to the application server. Using JSP Preview, you get a good idea of how the page will look before you have to deploy (see Figure B-29). Figure B-29. Quickly previewing JSP views in Exadel Studio APPENDIX B ■ STRUTS DEVELOPMENT TOOLS464 AppB_7389_CMP2 9/25/06 9:15 PM Page 464 [...]... inputfields, 107 108 element, 103 , 106 execute() method and, 106 value attribute, 106 element, 103 , 110 property attribute, 110 element, 98–99, 106 property attribute, 99 100 writing all error messages to JSP page, 98 writing single error message to JSP page, 99 element, 103 , 104 table of attributes, 105 element, 103 dropdownlists, 108 generating... generating option list from Collection object, 109 value attribute, 109 element dropdownlists, 108 name attribute, 109 element, 103 , 110 111 property attribute, 111 value attribute, 111 element, 103 dropdownlists, 108 property attribute, 109 element, 103 , 104 property attribute, 106 value attribute, 106 487 Ch16_Index_7389_CMP2 488 9/29/06 3:35... @struts. action-exception tag, 307 tag, 167 tag @struts. action-exception tag, 307 Hardwired antipattern, 16-18 Hashtable class lack of caching algorithms, 149 Ch16_Index_7389_CMP2 9/29/06 3:35 PM Page 487 ■INDEX element, 103 , 107 name attribute, 107 property attribute, 107 element, 103 , 107 cols attribute, 108 name attribute, 108 property attribute, 108 ... validation logic within, 101 problems in writing, 255 RequestProcessor class creates, 78 reset() method, 78, 81, 86–88, 101 strings, 117 using Validator Frameworkwithin, 273–275 validate() method, 36, 75, 78, 81, 101 , 117, 255, 274, 282 validating form data, 36, 93 without Java, 283–284 ActionForward class, 170, 396 org .apache. struts. action package, 47 ActionMapping class action mappings in Struts framework,... extending Struts Action class, 49 hot-deploy, 355–356 HTML (HyperText Markup Language) limitations, 5 HTML forms See forms HTML tag library, Struts best practices for ActionForms, 117 building more dynamic ActionForms, 111–116 business logic and ActionForms, 118–122 drop-down lists, 108 109 introduction, 103 setting up Struts HTML form, 104 107 strings and ActionForms, 117 table of elements, 103 TLD, 104 ... reducing with web development frameworks, 24 Tier Leakage, 13–15, 130–132 Tight Skins, 20–21 Validation Confusion, 18–19 AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis Brown et al, 9 AOP (Attribute-Oriented Programming) and XDoclet, 292 Apache Ant See Ant Apache Commons BeanUtils project utility classes, 119 Apache Jakarta Commons Digester project, 403 Commons Logging project,... BEA products, you might have heard of BEA WebLogic Workshop The first web application framework to use annotations was the Java Page Flow Controller framework, a feature of WebLogic Workshop BEA then donated the framework to open source, now known as the Apache Beehive project Pro Apache Beehive (Apress, 2005) is a good starting place if you are interested in this framework It is built on top of Struts. .. the manual supplied with the product is very detailed You will find that pretty much everything you need to know about the product is in the manual However, we would say that this isn’t a tool for Struts beginners If you are unfamiliar with how Struts works, we recommend you take the time to understand how the pieces of the framework fit together and how to put applications together without using a tool... Struts and Strecks S trecks is an extension to Struts that can only be used with Java 1.5 (Tiger) or later It is built on top of the 1.2.x codebase Strecks is not a replacement to Struts, but rather a layer of abstraction on top of it All the inherit concepts of Struts such as Action and Action Forms are still present, but in Strecks they are enhanced with some new functionality or are simplified with. .. project utility classes, 119 Apache Jakarta Commons Digester project, 403 Commons Logging project, 317, 320 Commons project, 266 Struts framework, 31 Validator framework, 266 Velocity template engine, 359 Velocity Tools project, 381 Apache JMeter See JMeter Apache log4j See log4j Apache Torque project, 187 tag, 333 appenders, log4j, 328–329 Application Controller pattern, 43 application development . 4.0. Struts Projects Exadel Studio adds a new project type to Eclipse, the Struts project, which you must use in order to take advantage of most of the features. When you start a Struts project,. configuration files. Editing the Struts Configuration File The file we want to look at editing with Struts Console is struts- config.xml. To open the struts- config.xml file in Struts Console, locate it. source, now known as the Apache Beehive project. Pro Apache Beehive (Apress, 2005) is a good starting place if you are interested in this framework. It is built on top of Struts and based totally

Ngày đăng: 12/08/2014, 22:22

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan