Exforsys

WebSphere Tutorials

  1. WebSphere V5.0 : Building Expressions
  2. WebSphere V5.0 : Creating SQL statements
  3. WebSphere V5.0 : Applying DDL scripts to a remote database
  4. WebSphere V5.0 : Deploying to the database
  5. WebSphere V5.0 : Defining a table
  6. WebSphere V5.0 : Defining a database
  7. Working with Data in WebSphere
  8. WebSphere V5.0 : Debugging - JSP debugging
  9. WebSphere V5.0 : Debugging - Scrapbook Page
  10. WebSphere V5.0 : Debugging - View variables
  11. WebSphere V5.0 : Debugging - Step-through code
  12. WebSphere V5.0 : Debugging - Set breakpoints
  13. WebSphere V5.0 : Running Applications - Export J2EE applications
  14. WebSphere V5.0 : Running Applications - Run/operate server
  15. WebSphere V5.0 : Running Applications - Understand Session Manager
  16. WebSphere V5.0 : Running Applications - Configure data sources
  17. WebSphere V5.0 : Running Applications - Create server instance and server configuration
  18. WebSphere V5.0 : Web Development - Use Web Page Wizards
  19. WebSphere V5.0 : Web Development - Work with Web Application Deployment Descriptor
  20. WebSphere V5.0 : Web Development - Use content assist
  21. WebSphere V5.0 : Web Development - Use Page Designer to add and modify HTML and JSP content
  22. WebSphere V5.0 : Web Development - Understand classpath and module dependencies
  23. WebSphere V5.0 : Web Development - Create resources in appropriate J2EE locations
  24. WebSphere V5.0 : Web Development - Create a web project
  25. WebSphere V5.0 : Java Development - Use property dialogues
  26. WebSphere V5.0 : Java Development - Use hierarchy view
  27. WebSphere V5.0 : Java Development - Use task view
  28. WebSphere V5.0 : Java Development - Use search function
  29. WebSphere V5.0 : Java Development - Use content assist function and declarations
  30. WebSphere V5.0 : Java Development - Use refactoring features
  31. WebSphere V5.0 : Java Development - Use Outline View and Browsing View
  32. WebSphere V5.0 : Java Development - Create Java project, packages, classes, methods
  33. WebSphere V5.0 : Workbench Basics - Use the Help feature to aid in development activities
  34. WebSphere V5.0 : Workbench Basics - Import to and export from the workbench
  35. WebSphere V5.0 : Workbench Basics - Work with Perspectives
  36. WebSphere V5.0 : Workbench Basics - Set workbench preferences
  37. WebSphere V5.0 : Workbench Basics - Create J2EE projects

Ads


Home arrow Reviews arrow WebSphere Tutorials

WebSphere V5.0 : Web Development - Use content assist

Author : Exforsys Inc.     Published on: 7th May 2006

WebSphere V5.0 : Web Development - Use content assist

Content assist helps finish a tag or line of code in the source editor. Content assist also enables you to select and insert macros in the Page Designer Source page. The placement of the cursor in the source file provides the context for the content assist to offer suggestions for completion.

Ads

Use content assist
Using HTML content assist

Content assist helps finish a tag or line of code in the source editor. Content assist also enables you to select and insert macros in the Page Designer Source page. The placement of the cursor in the source file provides the context for the content assist to offer suggestions for completion.

HTML is flexible, in that some HTML elements allow end tags to be optionally omitted, such as P, DT, DD, LI, THEAD, TR, TD, TH, and so on. Other HTML elements that are defined to have no content may require the end tag always be omitted, such as BR, HR, LINK, META, and IMG. This flexibility makes the content assist function within the Source page of the Page Designer less precise than it might be with a more rigidly constrained markup language.

HTML content assist is most beneficial when you need to complete a tag name, add an attribute name-value pair within a start tag, or select from an enumerated list of attribute values.

Although content assist only shows attribute names that have not already been specified in a start tag, it does not take into account grammar constraints for tags. For example, the HEAD element in HTML only permits zero or one occurrences of a TITLE tag in its content. If you prompt for content assist within a HEAD content that already contains a TITLE tag, content assist will still show TITLE in its proposal list.

However, if an attribute is required according to the DTD/Schema, that attribute will show up at the top of the list, with a yellow circle indicator on its icon.

You can request content assist in any of the following two ways:


From the Edit menu, select Content Assist, or

Press Ctrl + Space, or

In addition, you can set a preference that causes content assist to pop up automatically when certain characters are typed, such as < in the case of HTML and XML. To set this preference, select Preferences from the Window menu, and then select Web and XML Files > HTML Files > HTML Source. In the Content assist group box, select the Automatically make suggestions check box, and supply any additional characters that should trigger content assist.

If your cursor is in a position where content assist is available, a pop-up list of available choices is displayed. The list is based on the context. For example, if you use content assist directly after an opening paragraph tag (< P >), the first item in the content assist list will be the corresponding closing paragraph (< / P>) tag.

The content assist list displays all available tags for the current cursor position, including macros. The picture below shows the default content assist list for a paragraph tag example:

HTML Content Assist List

Tag proposals are listed alphabetically. If you type a < (to begin a new tag) before prompting for content assist, and begin typing the first one or two letters of the tag that you want to add, the proposal list automatically refreshes to reflect proposals that match the pattern you have typed. If you do not type a < before prompting for content assist, you can click within the proposal list and then type the letter that the tag begins with, to reduce (somewhat) the amount of scrolling to locate the desired tag.

As you type the first one or two letters of the attribute names or enumerated attribute values that you want to add to a tag, the list automatically refreshes to reflect proposals that match the pattern you have typed.

Using JSP content assist

All of the JSP tags are included both in the macro list and in XML format (for example, < jsp:expression >). To add JSP scriptlet tags, for example, move the cursor to the appropriate position in the file and press Ctrl + Space to use content assist. Select JSP scriptlet from the proposal list to insert "< % % >" in the document:

Content Assist List in JSP

Scriptlets are inserted in a tag "< % % >". For example:

< % System.currentTimeMillis(); % >

This example will evaluate the Java statement to get the current time in milliseconds.

To have the result of the statement inserted in the file, put an equals sign (=) in the front of the statement. For example:

< b >This is the time : < %= System.currentTimeMillis()% > < /b >

When you are within a scriptlet you are writing pure Java code. Therefore, content assist works exactly the same as it does for the Java editor. For example, if you request content assist after "System", content assist displays a list of methods:

Content Assist List in JSP

NOTE: Java content assist only works in a Web project, because it requires a buildpath to find the appropriate java classes.

In addition, there are special tags such as useBean. For example:

< jsp:useBean id="aString" class="java.lang.String" / >

The useBean tag enables you to create a bean called aString of type String. Then when you use content assist, this is recognized as a declared variable. For example, if you use content assist after aString, as follows:

< % aString % >

the content assist list shows available methods. This is because aString has been declared as a bean of type String.

< % a % >

If you use content assist after the a, as follows:

content assist knows that aString exists, and it is shown in the content assist list:

Content Assist List in JSP

Using the workbench, you have many options for adding greater functionality and embedded Java code to your JSPs.

Using JavaScript content assist

Content assist helps finish a tag or line of code in the source editor. The placement of the cursor in the source file provides the context for the content assist to offer suggestions for completion.

You can request content assist in any of the following three ways:

  • From the Edit menu, select Content Assist, or
  • Press Ctrl + Space, or
  • Right-click and select Content Assist from the context menu.

In addition, you can set a preference that causes content assist to pop up automatically when certain characters are typed, such as "." in the case of JavaScript. To set this preference, select Preferences from the Window menu, and then select Web and XML Files > JavaScript Files > JavaScript Source. In the Content assist group box, select the Automatically make suggestions check box, and supply any additional characters that should trigger content assist.

JavaScript Content Assist Preferences

If your cursor is in a position where content assist is available, a pop-up list of all available choices is displayed. For each of these choices, a brief description of the tagging is provided.

Items in the content assist list are preceded by an Internet Explorer icon, a Netscape icon, or both, to indicate whether specific JavaScript objects, methods, or attributes are supported by one or both browsers. If the Internet Explorer icon is present, it indicates that the object, method, or attribute is supported by Internet Explorer Version 5.0 or higher. If the Netscape icon is present, it indicates that the object, method, or attribute is supported by Netscape Version 4.7 or higher. A question mark icon in place of one of the browser icons indicates that it is unknown whether the browser supports the object, method, or attribute.

The picture below shows the default content assist list within a JavaScript file:

JavaScript Content Assist

Ads

Code proposals are listed alphabetically. If you type a "." (include the space) before prompting for content assist, and begin typing the first one or two letters of the code that you want to add, the proposal list automatically refreshes to reflect proposals that match the pattern you have typed, to reduce (somewhat) the amount of scrolling to locate the desired code.

_____________
Author: Mikalai Zaikin. Please Click Here to visit Authors site for any updates and changes to the study notes.



 
This tutorial is part of a WebSphere Tutorials tutorial series. Read it from the beginning and learn yourself.

WebSphere Tutorials

  1. WebSphere V5.0 : Building Expressions
  2. WebSphere V5.0 : Creating SQL statements
  3. WebSphere V5.0 : Applying DDL scripts to a remote database
  4. WebSphere V5.0 : Deploying to the database
  5. WebSphere V5.0 : Defining a table
  6. WebSphere V5.0 : Defining a database
  7. Working with Data in WebSphere
  8. WebSphere V5.0 : Debugging - JSP debugging
  9. WebSphere V5.0 : Debugging - Scrapbook Page
  10. WebSphere V5.0 : Debugging - View variables
  11. WebSphere V5.0 : Debugging - Step-through code
  12. WebSphere V5.0 : Debugging - Set breakpoints
  13. WebSphere V5.0 : Running Applications - Export J2EE applications
  14. WebSphere V5.0 : Running Applications - Run/operate server
  15. WebSphere V5.0 : Running Applications - Understand Session Manager
  16. WebSphere V5.0 : Running Applications - Configure data sources
  17. WebSphere V5.0 : Running Applications - Create server instance and server configuration
  18. WebSphere V5.0 : Web Development - Use Web Page Wizards
  19. WebSphere V5.0 : Web Development - Work with Web Application Deployment Descriptor
  20. WebSphere V5.0 : Web Development - Use content assist
  21. WebSphere V5.0 : Web Development - Use Page Designer to add and modify HTML and JSP content
  22. WebSphere V5.0 : Web Development - Understand classpath and module dependencies
  23. WebSphere V5.0 : Web Development - Create resources in appropriate J2EE locations
  24. WebSphere V5.0 : Web Development - Create a web project
  25. WebSphere V5.0 : Java Development - Use property dialogues
  26. WebSphere V5.0 : Java Development - Use hierarchy view
  27. WebSphere V5.0 : Java Development - Use task view
  28. WebSphere V5.0 : Java Development - Use search function
  29. WebSphere V5.0 : Java Development - Use content assist function and declarations
  30. WebSphere V5.0 : Java Development - Use refactoring features
  31. WebSphere V5.0 : Java Development - Use Outline View and Browsing View
  32. WebSphere V5.0 : Java Development - Create Java project, packages, classes, methods
  33. WebSphere V5.0 : Workbench Basics - Use the Help feature to aid in development activities
  34. WebSphere V5.0 : Workbench Basics - Import to and export from the workbench
  35. WebSphere V5.0 : Workbench Basics - Work with Perspectives
  36. WebSphere V5.0 : Workbench Basics - Set workbench preferences
  37. WebSphere V5.0 : Workbench Basics - Create J2EE projects
 

Comments