Code clips are snippets of code in the
that you can use in your applications. You can insert a code clip into
code that is open in an IDE source editor, such as the Java
Editor or the JSP Editor. You can also add new code clips to the Palette
from any editor. In addition, you can rename, edit, or delete code
clips in the Palette.
The Code Clips palette has the following categories:
Database. Clips used to provide functionality
for applications using databases and web services, such as clips to access
the first, next, and previous rows in an application.
Application Data. Clips used to access values in the application,
such as clips to retrieve values from a session.
Web App Functions. Clips used to perform common web application
functions, such as sending email.
Java Basics. Clips used to perform common Java programming tasks, such as loops.
EnterpriseJavaBeans. Clips used for applications using Enterprise beans.
To use a clip in your code:
Open your code in the Java Editor or the JSP Editor, depending on the type
of code clip and where you want it to go.
Drag the code clip from the Palette to the location where you want it in the source
editor.
To add a clip to the Palette by dragging a selection:
With the source file open in the Java or JSP editor, drag the cursor to select the code you want to make into a clip.
Ctrl-Click in the selected area and drag the code to the Palette category where you want the clip to be listed.
If you click and drag without holding down the Ctrl key, the code segment will be cut (deleted) from the source file. Be sure to press and hold the Ctrl key during the drag and drop operation so the code will be copied and not cut.
Right-click the new code clip in the Palette and choose Rename to give it an appropriate name.
To add a clip to the Palette by typing code:
In the Code Clips view of the Palette, right-click the category where you want
to add the clip and choose Create New Code Clip.
In the Code Clips Editor, type the text.
Click Save Changes.
Right-click the new code clip in the Palette and choose Rename to give it an appropriate name.
To edit a clip:
In the Palette, right-click the code clip and choose Edit Code Clip.
In the Code Clips Editor, edit the text and click OK.
If you edit one of the code clips supplied with the IDE, you might see a construct in the comments like the following:
// ~TravelPrerender1~
These comments expand into text when the code clip is added to your code. Do not delete them if you want to preserve the code clip's original comments.
To delete a clip:
In the Palette, right-click the code clip and choose Remove.
To add a category to the Code Clips view:
Right-click any category and choose Create New Category.
Enter the name of the new category in the New Palette Category dialog box, and then
click OK.
To delete a category from the Code Clips view:
Right-click the category you want to delete and choose
Delete Category.
When the delete confirmation dialog box appears, click Yes.
As stated in the confirmation dialog box, any code clips in the category
will be deleted when you delete the category.