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:

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.

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


<% a %>
					
					
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:

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

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.

Professional hosting     Belorussian informational portal         Free SCWCD 1.4 Study Guide     Free SCBCD 1.3 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     Free Mock Exam Engine