The IDE's Source Editor provides many features that make the typing and changing of code for various web application components easier. This section goes over a few of the features that are particularly useful for web applications. See Chapter 5 for more information on IDE editing and refactoring features. Completing TagsThe IDE enables you to have tags and tag attributes completed automatically in JSP, HTML, and XML files. The tag completion feature not only reduces the number of keystrokes that you type, but also provides popup documentation for the possible ways to complete the tag or attribute that you are typing, as shown in Figure 8-4. Figure 8-4. The code completion feature in a JSP fileOpen the tag completion popup by typing the beginning of a tag and pressing Ctrl-spacebar or waiting a second for code completion to kick in automatically. If there is only one way to complete the word you are typing, the end of the word is filled in automatically. If there are multiple ways to complete the tag, a popup list of those possibilities is displayed. You can keep typing to narrow the list or select the text you want, using the mouse or arrow keys. For example, if you want to add the following statement in a JSP file <jsp:useBean scope="page" /> you can enter it in the following steps (don't worrythe number of steps illustrated here may seem daunting, but it is only because they are presented in such minute detail):
See Generating Code Snippets in Chapter 5 for information on completing Java expressions and configuring code completion. Using Code Templates for JSP FilesFor commonly used JSP code snippets, you can take advantage of code templates in the Source Editor to reduce the number of keystrokes. You can access a JSP code template by typing the abbreviation for the code template and then pressing the spacebar. See Table 8-3 for a list of code templates for JSP files. Code templates are available for other types of files as well. See Chapter 5, Table 5-1, for a list of code templates for Java classes.
If an abbreviation for a code template is the same as text that you want to type (for example, you do not want it to be expanded into something else), press Shift-spacebar to keep the text from expanding into the code template. You can modify the list of code templates in the Options window. See Adding, Changing, and Removing Code Templates in Chapter 5. Editing the Deployment Descriptor ManuallyAlthough the IDE guides you through the adding of entries for the deployment descriptor (web.xml file) as you add servlets, filters, and listeners to your project, you might have occasion to edit the file by hand. To open the deployment descriptor in the Source Editor, open the Projects window, expand the Configuration Files node (or the Web Pages | Web-INF node), and double-click the web.xml file. The file opens as a multitab document in the Source Editor with the General tab open (as shown in Figure 8-5). You can edit different parts of the web.xml file with the visual editors for different elements of the file (General, Servlets, Filters, and Pages), or you can click the XML tab to edit the file's XML source directly (see Figure 8-6). Figure 8-5. Deployment descriptor visual editorFigure 8-6. Deployment descriptor XML editorRefactoring Web ComponentsNetBeans IDE's refactoring support extends to web applications and enterprise applications. For example, you can do the following:
When you rename a web component class (such as a servlet or tag handler), any corresponding name entries in the application's deployment descriptor (web.xml file) and/or tag library descriptor (TLD) are updated as well. When you move a class and the deployment descriptor is affected, you are prompted with a Confirm Changes dialog box to make sure that you want to process changes to the deployment descriptor.
|