Track taglib ver. 1.2

    Custom JSP taglib. Tags let you to track changes for some data. You can use this for example on constantly refreshed pages etc.

For example:
 


<%@ taglib uri="taglib.tld" prefix="track" %>

<track:trackValue key="12345" value="<%=your_expression%>">
   <script language="JavaScript">
    alert('Value has been changed');
   </script>
</track:trackValue>

How does it work? This tag defines a new track for data. Each track must have own unique key. During the first execution tag saves the value for your_expression. For the each next execution tag updates the saved value and compares it with the previous one. As soon as the value has been changed tag will execute own body too. In this example it will popup JavaScript alert.

By default tag assumes that your expression describes some String value. You can define your method for comparing. Parameter cond describes a boolean expression where true value is a signal about data changing:
 


<track:trackValue key="my_key" value="<%=your_expression%>" cond="<%=booleanFunction()%>">
   <script language="JavaScript">
    alert('Value has been changed');
   </script>
</track:trackValue>

For this function you can read the old value by this way: session.getAttribute("your_key"). For example by default tag uses this expression for cond parameter: <%=!((String)value).equals((String)(session.getAttribute("your_key")))%>

As a live example for this tag you can see JMX console where this taglib helps to monitor attributes of MBeans.

Tags are:

trackValue

Body tag updates monitored data and executes own body if data has been changed. Parameters are:

1) key describes a key
2) value describes a new value
3) cond Optional parameter. Describes a custom boolean expression that compares the current value and the old one. True value is an indicator for data changing.

isTrackValue

Body tag executes own body if key describes some monitored data. Parameters are:

1) key describes a key

isNoTrackValue

Body tag executes own body if key does not describe monitored data. Parameters are:

1) key describes a key

getTrackValue

Prints or saves in the page scope variable current value. Parameters are:

1) key describes a key
2) id Optional parameter. Describes a name for page scope variable (type is java.lang.Object). By default tag just prints requested values

removeTrackValue

Stops monitoring. Parameters are:

1) key describes a key

for downloading:

Library: tracktag.jar    Description: taglib.tld

© Coldbeans      Comments?

See also Coldtags suite - the largest collection of custom JSP tags.