Content assist

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

Most of the structured text editors have content assist. For a list of editors that have content assist, refer to Editing source code. For information on configuring content assistance, refer to Configuring structured text editor preferences.

The following sections describe specifics of:
HTML content assist
JavaScript content assist
JSP content assist

HTML content assist

HTML is flexible in that some HTML elements enable 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 might require the end tag to always be omitted, such as BR, HR, LINK, META, and IMG. This flexibility makes the content assist function within the HTML source page editor 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 shows only attribute names that are not already specified in a start tag, it does not take into account grammar constraints for tags. For example, the HEAD element in HTML permits only zero or one occurrence 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 still show TITLE in its proposal list; however, TITLE is de-emphasized in the list.

However, if an attribute is required according to the DTD/Schema, that attribute appears on the list with a yellow circle indicator on its icon.

If your cursor is in a position where content assist is available, a 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 is the corresponding closing paragraph (</p>) tag.

The content assist list displays all available tags for the current cursor position, including templates. The following image shows the default content assist list for a paragraph tag example:

HTML Content assist

Tag proposals are listed alphabetically. If you type a < to begin a new tag before you prompt for content assist, type the first few letters of the tag, the proposal list automatically refreshes to reflect proposals that match the pattern you typed. If you do not type a < before you prompt for content assist, you can click within the proposal list and then type the first letter in the tag to reduce the amount of scrolling.

As you type the first few 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 typed.

Restriction: For Linux. When you use Linux (Motif or GTK) and a DBCS locale, double-clicking the content assist list can sometimes cause the Java™ VM to terminate. Instead of double-clicking the list, use the arrows and Enter keys to make the selection from the list.

JavaScript content assist

Code proposals are listed alphabetically. If you type a period followed by a space before you prompt for content assist and begin to type the first few letters of the code, the proposal list automatically refreshes to reflect proposals that match the pattern you typed to reduce the amount of scrolling.

JSP content assist

You have many options for embedding Java and HTML code in your JSP pages by using content assist.

All of the JSP tags are included both in the template 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 content assist from the proposal list to insert <% %> in the document.

Scriptlets are inserted in a tag <% %>. For example:
<% System.currentTimeMillis(); %>

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

To insert the result of the statement into 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 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.
Note: Java content assist works only in a web project because it requires a buildpath to find the appropriate Java classes.
There are also special tags such as useBean. For example:
<jsp:useBean id="useBean" class="java.lang.String"/>

Using the useBean tag, you can create a aString bean of type String. When you use content assist, this bean is recognized as a declared variable. For example, if you use content assist after <% aString. %>, the content assist list shows available methods because aString is declared as a bean of type String.

If you use content assist after <% a %>, content assist knows that aString exists, and it is shown in the content assist list.

Icon that indicates the type of topic Concept topic
Timestamp icon Last updated: July 17, 2017 21:58

File name: csrcedt006.html