Tips & Tricks - Speedometer

The "Tachometer" application element is suitable for displaying speeds, volume levels, pressure, temperature or fill levels. This workshop will demonstrate how to display the number of users currently logged in to the portal using the gauge.

You can download the sample application here and then import it as usual.

Velocity file for initialization

The example application only contains one page.

The "Velocity template for initialization" option is selected on the "General" tab in the properties dialog for this page. This integrates the Velocity template "usersOnline.vmi". The Velocity template's task is to determine the number of logged in users and then save this value to the sharedState so that the gauge control can access this value.

            $Response.setIgnoreWrite(true)
#set($userList = $Portal.getUsersOnline(false))
#set($userSet = $CollectionFactory.createSet())
$userSet.addAll($userList)
$SharedState.putAt("usersOnline",$userSet.size())
$Response.setIgnoreWrite(false)

        

Configure gauge

You will find the speedometer element on the "User Online" page. The data to be displayed in the speedometer is set in the "Speedometer" tab of the properties dialog. The static value 0 is well-suited as a starting value. The static value 1000 is selected as the ending value in our example. You could also get the total number of users from the database, save this value to the sharedState and read it in the properties of the ending value. The system value "usersOnline" from the processing context (the SharedState) is used for the displayed value.

If desired, the "User Online" page can also be defined as a portlet and added to portal pages.