close

Filter

loading table of contents...

Studio Developer Manual / Version 2101

Table Of Contents

7.27.6 REST Linking (Studio RemoteBeans)

Since you have created another EntityController, you have to declare the matching remote beans the same way you already did for the Note remote bean. That means, you have to declare the interface

public interface Notes extends RemoteBean {

  function getNotes():Array;
}

Example 7.116. Interface for remote bean for notes list


and the implementing class

[RestResource(uriTemplate="notes")]
public class NotesImpl extends RemoteBeanImpl implements Notes {

  public function NotesImpl(uri:String) {
    super(uri);
  }

  public function getNotes():Array {
    return get('notes');
  }
}

Example 7.117. Implementing class for remote bean for notes list


and finally tell Studio that a new remote bean type is there. So the configuration section of your custom Studio plugin would look like:

<editor:configuration>
  <editor:RegisterRestResource beanClass="{NoteImpl}"/>
  <editor:RegisterRestResource beanClass="{NotesImpl}"/>
</editor:configuration>

Example 7.118. Register remote bean with Studio


Rebuild and reload Studio. Once you are logged in, test the new REST controller manually by invoking the following URL in another browser tab: http://localhost:43080/rest/api/notes/ (the path may differ depending on your setup). As a result, you should see the following:

{
  notes: [
    {
      $Ref: "notes/note/1"
    },
    {
      $Ref: "notes/note/2"
    }
  ]
}

Example 7.119. Test result of remote bean


Note that not the plain JSON of the entities is serialized, but the references to them instead. For every class that is part of a representation a lookup is made if there is a corresponding EntityController declared for it. If true, the link to this controller is serialized instead of the linked entity.

Warning

Warning

The serialization and deserialization of entities consumed or produced by the EntityController is never handled by the controller itself. Please do not make any assumptions on how serialization and deserialization is implemented in your code, as this is not part of the Public API.

Invoke this inside ActionScript:

var notes:Notes = beanFactory.getRemoteBean('notes') as Notes;
notes.load(function(loadedNotes:Notes):void {
  trace('I have ' + loadedNotes.getNotes().length + ' notes');
});

Example 7.120. Invoke notes in ActionScript


The code looks similar to the previous example. The matching remote bean is created and loaded and the status of the bean is logged to the console. Note that only the Notes bean has been loaded through this code. The child elements must be loaded separately, so to display everything you can do something like this:

var notes:Notes = beanFactory.getRemoteBean('notes') as Notes;
notes.load(function(loadedNotes:Notes):void {
  trace('I have ' + loadedNotes.getNotes().length + ' notes');

  loadedNotes.getNotes()[0].load(function(note1:Note):void {
    trace(note1.getDescription());
  });

  loadedNotes.getNotes()[1].load(function(note2:Note):void {
    trace(note2.getDescription());
  });
});

Example 7.121. Display child elements of notes list


The output will look like this:

AS3: I have 2 notes
AS3: I have to write a real storage for this!
AS3: And a lot of other stuff too!

Example 7.122. Output of notes list


Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.