Tips & Tricks - Speedometer
The "Tachometer" widget is suitable for displaying speeds, volume levels, pressure, temperature, or fill levels. This post shows how to use the speedometer to display the number of users logged in to the portal.
You can download the sample application here and then import it as usual.
Velocity Template for Initialization
The sample application contains only one page.
In the Properties dialog box on this page, the "Velocity Template for Initialization" option is selected on the "General" tab. This integrates the Velocity template "usersOnline.vmi. " The Velocity template is responsible for reading the logged-in users and temporarily storing the count in `sharedState` so that this value can be accessed from the speedometer control.
$Response.setIgnoreWrite(true)
#set($userList = $Portal.getUsersOnline(false))
#set($userSet = $CollectionFactory.createSet())
$userSet.addAll($userList)
$SharedState.putAt("usersOnline",$userSet.size())
$Response.setIgnoreWrite(false)
Adjusting the Speedometer
On the "Users Online" page, you'll find the speedometer widget. In the Properties dialog box, on the "Speedometer" tab, you can specify which data should be displayed on the speedometer. The static value 0 is a suitable starting value here. For this example, the value 1000 is chosen as the final value. You might just as well retrieve the number of users from the database and store it temporarily in SharedState. The system value "usersOnline" from the processing context (SharedState) is used for the displayed value.
If desired, the "Users Online" page can also be defined as a portlet and added to portal pages.


