NaturalONE Version 8.3.7
 —  Natural for Ajax  —

NJX:OBJECTS

The NJX:OBJECTS control is used to make assets that are contained in Natural binary variables (BLOBs) available to controls on the web page. Examples are images in arbitrary controls such ICON, IMAGEOUT, CLIENTTREE or MENU.

The following topics are covered below:


General Information

In the Natural program, the NJX:OBJECTS control is represented with the following data structure:

1 XCIOBJECTS (1:*)
2 CONTENT (B) DYNAMIC
2 CONTENTID (A) DYNAMIC
2 CONTENTTYPE (A) DYNAMIC

With this data structure, images and other binary content can be transported from the Natural program to the application server or web container.

For each entry in the data structure, the following must be specified: the binary content itself, an identifier and (optionally) the content type. In your Natural program, you only add the binary content once, with a specific name. The binary content is then automatically cached in the application server or web container until the Natural application completes its execution. During a server roundtrip from Natural to the application server or web container, all binary content that is found for this data structure is added to the cache and the data structure is cleared. After a server roundtrip, the data structure is always empty.

When referencing binary content such as an image from within a control of your page layout, you usually specify an URL. For Natural binary content, the URL starts with the prefix "nat:" followed by a name. To reference binary content from within a design-time property such image in a control of your page layout, you specify this URL directly in your page layout. For example:

...
<icon image="nat:icon01">
</icon>
...

When referencing binary content using a dynamic property such as imageprop, you can use automatically generated names.

In both cases (when you apply the URLs to properties statically at design-time and when you apply the URLs dynamically at runtime), you do not have to work directly on the XCIOBJECTS structure. Instead, you can use the helper subprogram MAKEURL which can be found in the Natural for Ajax demos. You can use your own names or you can leave it to the helper subprogram MAKEURL to generate the names. The MAKEURL subprogram adds a corresponding entry to the XCIOBJECTS data structure and returns an URL for this binary content. When the CALLNAT statement in the example below has been executed, the MYURL field contains a valid URL which you can apply to dynamic image properties (for example, in a grid or other dynamic controls).

DEFINE DATA LOCAL
1 MYURL (A) DYNAMIC
1 XCIOBJECTS (1:*)
2 CONTENT (B) DYNAMIC
2 CONTENTID (A) DYNAMIC
2 CONTENTTYPE (A) DYNAMIC
...
LOCAL
1 MYBLOB (B) DYNAMIC
...
END-DEFINE

CALLNAT "MAKEURL" XCIOBJECTS(*) MYBLOB MYURL

If you want to use your own name (for example, "icon01"), you have to specify the CALLNAT statement as follows:

CALLNAT "MAKEURL" XCIOBJECTS(*) MYBLOB MYURL "icon01"

Optionally, you can explicitly specify the content type. This is required for content types which are not automatically recognized by the browser. Example:

CALLNAT "MAKEURL" XCIOBJECTS(*) MYBLOB MYURL "icon01" "gif"

Note:
See also Images in Some Common Rules for all Controls.

Top of page

Example

Examples which show the usage of the NJX:OBJECTS control are provided in the Natural for Ajax demos: the programs CTROB1-P and CTROB2-P.

Top of page

Adapter Interface

1 XCIOBJECTS (1:*)
2 CONTENT (B) DYNAMIC
2 CONTENTID (A) DYNAMIC
2 CONTENTTYPE (A) DYNAMIC
Element Description
CONTENT The binary content as contained in a Natural binary variable.
CONTENTID A name used for caching in the application server or web container and for referencing the content from within an URL.
CONTENTTYPE The content type as understood by a browser. For content types which are not automatically recognized by a browser, the content type has to be specified.

Top of page