Skip to content

rad var

Steve Hannah edited this page Jul 9, 2021 · 1 revision

rad-var attribute

Synopsis

Attribute that can be added to any component in a RAD view, which adds a reference to the component as a member variable on the view. This is an easy way to access the component from Java expressions in the page. E.g. inside <script> tags, and attributes with Java expressions.

Usage

<someComponent rad-var="[+|-]varName" …​/>

The varName can be optionally prefixed with - or + to make the variable either public or private. Default scope is package private.

Examples

Consider the following:

<textField rad-var="usernameField"/>

This would result in the following member variable being defined in the view’s class:

TextField usernameField;

And this would be set to a reference to the given <textField> when it is created.

You could then access the text field from within a script tag on the page:

<script><![CDATA[
usernameField.addActionListener(evt->{
    System.out.println("Username is "+usernameField.getText());
});
]]></script>

Example Private Variable

To make the variable private, just prefix the var name with -. E.g.

<textField rad-var="-usernameField"/>

This would result in the following member variable being defined in the view’s class:

private TextField usernameField;

Example Public Variable

To make the variable public, just prefix the var name with +. E.g.

<textField rad-var="+usernameField"/>

This would result in the following member variable being defined in the view’s class:

public TextField usernameField;
Clone this wiki locally