This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Starting Java business logic and IIZI Development

Starting Java business logic and IIZI Development

What does it mean?

If your web application includes Java code from a previous project or has been partially developed in another IDE, you can paste your Java code and folder structure into iiziGo after creating a new IIZI Quickstart project. During deployment for distribution, all directories and libraries are packed into your iiziApp.

Having started with Quickstart, a main Java class is created for you in the src package. This has been named with your IIZI project’s name, and contains the minimal IIZI Annotations necessary for integrating your Java code into your iiziApp; you can connect your Java project through this class. At present – version 1.0 – only one Java class can serve as the annotated entry point for a VirtualSpace or a UI Panel.

@VS (ref= "MyApp:/vs/start")
public class StartNameSpaceListener {

  @OnVSChange (name="fld")
  public void onChange (VSChangeEvent event) {
  }

  @OnVSFocus (name="input")
  public void onFocus (VSFocusEvent event) {
  }

  @OnVSAction (name="my-Action")
  public void onAction (VSActionEvent event) {
  }
}

A Java class annotation and three annotated Java methods

All references to IIZI elements are made using a reference path name in the following format: module:/path/name. Java code is updated and changed using Eclipse refactoring mechanisms whenever required.

Your Java classes can be annotated to a VirtualSpace directly while your Java methods will have annotations to VirtualSpace entities. In the IIZI Platform you do not normally add the listeners that are common in UI programming; instead, you connect a method to the place requiring the specific functionality.

1 - Java class and method connections

Java class and method connections

[Need a Text update on bottom]

There is a tutorial video just down below.

Your Java code can be connected to the VirtualSpace through a Java class that uses the IIZI Annotations for Java shown above.

Creating annotations for a class is automatic when you create a class through the Java Class property in the Property Editor. The IIZI Annotation is created with the class. With this automated approach, iiziGo has already created a back reference for the VirtualSpace participant.

Creation of a new Java class for a VirtualSpace

Creating annotations for a method is also automatic when you create a method through the properties of a VirtualSpace entity in the VirtualSpace Editor. In the example below, the method will be connected to the OnVSChange property of a vsGroup. The IIZI Annotation is created with the method, and the method is created with the correct Java Method Signature. With this automated approach, iiziGo has already created a back reference for the VirtualSpace participant. It is recommended to use Ctrl-shift-S, Save All, frequently, as you make major changes to your Panels, Text tables and VirtualSpace entities. This will enable iiziGo to update the many references needed to maintain live connections between your source code, Panels and VirtualSpace.

We need to add texts here !!!

2 - VirtualSpace Actions and Java methods

VirtualSpace Actions and Java methods

UI components with click action events, typically buttons or menu items, have a VS Action property listed under Action in the Property Editor. For common interactions between components and Java methods, create a vsAction in your VirtualSpace and connect the vsAction to your Java method.

Creating a vsAction on a UI component through the component’s properties view

With the vsAction selected in the VirtualSpace Editor, search the Property Editor for the Connectors section; here, in the value field of the OnVSAction property, click the more menu and select a Java method or create a new method.

Create or assign a Java method to a vsAction in the properties view of the VirtualSpace editor

3 - Attaching methods to VirtualSpace entities

Attaching methods to VirtualSpace entities

You can attach a Java method to react to any changes in a VirtualSpace entity’s instance value, as well as any changes to its state, by specifying a method name for OnVSChange. To listen to focus changes, use OnVSFocus. The method name specified must be present in the class that is attached to the VirtualSpace. You chose the method name, but your custom method must have the respective Java Method Signatures:

@OnVSChange(name="componentPath")
public void onChange (VSChangeEvent event)

@OnVSFocus(name="componentPath")
public void onFocus (VSFocus event)

The method name editor has a more button that drops down a menu to help you to create a new method, to select an existing method, or to define or fix the method annotation with the correct componentPath.

4 - Attaching methods to VirtualSpace events

Attaching methods to VirtualSpace events

A Java method and its annotation are automatically created when adding a method to the VirtualSpace event in the VirtualSpace Property Editor. In this example, we will attach a method to the OnVSFocus First assign a vsGroup to the state and focus property of a Panel. With the vsGroup selected in the VirtualSpace Editor, the Property Editor displays the Connectors section in which you can choose from the following events: OnVSCreate, OnVSDestroy, OnVSFocus, OnVSChange, and OnVSState. By clicking the more button to the right of the OnVSFocus property, you can create a new Java method – with the correct annotation – that will be called every time your Panel gains focus or loses focus.

Below is a simple Java method created through the Property Editor to react to the OnVSFocus event. The method tests the property isFocusGained in which the IIZI API method setScreenOrientation is called. For the inverse case, when focus is lost, the unlockScreenOrientation method in called. Notice that the main VirtualSpace itself is referenced in the Java class, and that the client session is accessed by a reference to the IIZI Client Gyro.

Create or assign a Java method to a vsAction in the properties view of the VirtualSpace editor

5 - Back reference problems

Back reference problems

When connecting a method or class to the VirtualSpace from the Java code editor, the back reference will be missing. In this case – and at any time you find that a back reference is missing – one can be added by opening the VirtualSpace and selecting the back references enable clean debugging while in development.

You can add any missing annotation from VirtualSpace and panels to the code by:

  • Adding missing annotation
  • File > Save all or use CTRL + SHIFT + S

6 - UI Annotations

UI Annotations

Another form of annotation that exists in iiziGo is the UI Annotation. To access any of the UI Component Events in your Java code you must first set the Events property on the component’s Panel. A UI Annotation will be added to your Java class. Then you can set a Java method to respond to any of the familiar UI events by assigning a value to a component’s UI event. A UI Annotation will be added to your Java Method.

Creating or selecting Java methods through a component’s Events property

In the following example, we will add a Java method to the UI Event, OnUICreate; our method will lock the mobile device orientation when the Panel is created. A Java method and its annotation are automatically created when adding a method to a UI Event in the Panel’s Property Editor. With the Panel selected in the Property Editor, the Property Editor displays the Events section in which you can choose from the UI Events listed above. By clicking the more button to the right of the OnUICreate property, you can create a new Java method – with the correct annotation – that will be called when your Panel is created. And by doing the same when it is destroyed. Notice that the client session is accessed on the event by a reference to the IIZI Client Gyro.

Creating classes in the panel’s property editor

Common UI Events

OnUICreateOnUIValueChange
OnUIDestroyOnUIAction
OnUIConnectOnUISelection
OnUIBackOnUITextChange
OnUIFocus
Creating or selecting Java methods through a component’s Events property

In the following example, we will add a Java method to the UI Event, OnUICreate; our method will lock the mobile device orientation when the Panel is created. A Java method and its annotation are automatically created when adding a method to a UI Event in the Panel’s Property Editor. With the Panel selected in the Property Editor, the Property Editor displays the Events section in which you can choose from the UI Events listed above. By clicking the more button to the right of the OnUICreate property, you can create a new Java method – with the correct annotation – that will be called when your Panel is created. And by doing the same when it is destroyed. Notice that the client session is accessed on the event by a reference to the IIZI Client Gyro.

A Java methods for locking screen orientation triggered by the UI events

/***
* Auto-generated OnUICreate for panel or its components.
*/
@OnUICreate(name="nameOfPanel")
public void onUICreate (UICreateEvent event) {
  ScreenOrientation lockPortrait = ScreenOrientation.portrait;
  event.getClientSessionGyro().setScreenOrientation(lockPortrait);
}
/***
* Auto-generated OnUICreate for panel or its components.
*/
@OnUIDestroy(name="nameOfPanel")
public void onUIDestroy (UIDestroyEvent event) {
  virtualSpace.getClientSessionGyro().unlockScreenOrientation();
}

7 - Location of code

Location of code

The application code can reside in Module projects, Java projects, libraries and directories. When the application distribution is created, it is packed into a single iiziApp using the Application Distributor, see separate chapter.

Java code plays an important role in for an iiziApp. To build application logic into the iiziApp, it needs to refer to various parts. All references to IIZI elements are done using a reference name that looks like module:/path/name. This reference can have the module defined as . to refer to the current project where the Java code resides.

8 - Available APIs in iiziGo

Available APIs in iiziGo

The many methods exposed by the IIZI Platform API are available to you through Eclipse’s Java code completion. The IIZI Core and Plugin Libraries are not visible in the iiziExplorer, but only in the Eclipse Java Perspective. For the complete IIZI Platform Java API Specification see the IIZI Java API reference at https://support.iizi.co.

You can also access the JavaDoc from your local installation, generally using port 2800 using the link http://localhost:2800/ and selecting the JavaDoc link on the displayed page.