You are on page 1of 10

Symbolic Variables

Laurent Guérin / v 1.0 / 2009 - May

What are symbolic variables ?


 The symbolic variables are a set of predefined
expressions for accessing server information in a
Telosys tag attribute
 The variables are replaced by their value when the
JSP is called
 Syntax :
 @{ variable_name, default_value, format }
 Examples :
<t:out v="code : @{agency1.code} - city : @{agency1.city}" />

<t:listrow onclick="alert('count=@{#count,,000} city=@{.city,???}')" >

Telosys framework - Symbolic variables ( Laurent Guérin ) 2

Telosys 1
What are symbolic variables ?
 The symbolic variables are completely
independent of the standard JSP Expression
Language ( "EL" ). They can be used even in old
Java servers that doesn't support EL and JSTL.
 Where can they be used ?
 In the "v" attribute of "t:out"
 In every event attributes : onclick, onblur, …
 In the specific following attributes :
id name
value txt valueoff
title zone checked
cl style selected
disabled readonly
Telosys framework - Symbolic variables ( Laurent Guérin ) 3

Symbolic variables : predefined values


 Predefined names : "#xxx"
 Session & User
 @{#session-id} the current session id
 @{#user-login} the current user login
 @{#user-language} the current user language
 @{#user-role} the current user role
 URL & URI
 @{#webapp-url} "http://localhost:8080/appli/"
 @{#webapp-uri} "/appli/"

 @{#screenmap-url} "http://localhost:8080/appli/screenmap"
 @{#screenmap-uri} "/appli/screenmap"

Telosys framework - Symbolic variables ( Laurent Guérin ) 4

Telosys 2
Symbolic variables : predefined values
 HTTP request parameters :
 @{#paramcount} number of parameters
 @{#param-xxx} value of the "xxx" parameter

 Iterations :
 @{#count} the current count value ( from 1 to n )
 @{#count-parity} "even" or "odd"

 @{#index} the current index value


from index-base (0 by default) to n
 @{#index-parity} "even" or "odd"

Telosys framework - Symbolic variables ( Laurent Guérin ) 5

Symbolic variables : predefined values


 Screen Context :
 @{#context-id} 0 to N
 @{#context-name} "MYSCREEN" ( from ScreenContext registry )

 Screen Map ( from "screens.xml" ) :


 @{#screen-name} "S002"
 @{#screen-type} "html" or "xul"
 @{#screen-path} "/screen/tpl/html/model1.jsp"
 @{#screen-body} "S002.jsp"
 @{#screen-body-path} "/screen/S002.jsp"
 @{#screen-css} "S002.css"
 @{#screen-css-path}
 @{#screen-js} "S002.js"
 @{#screen-js-path} "/screen/script/S002.js

Telosys framework - Symbolic variables ( Laurent Guérin ) 6

Telosys 3
Symbolic variables for Java beans
 Any Java bean can be accessed with the standard
"dot" notation :
 @{agency.city} value of the attribute "city" of the bean
"agency"
 @{.city} value of the attribute "city" of the "current
bean" ( the "." in first position defines an attribute )
 @{agency} string value of the bean "agency"
( using the "toString" method of the bean )

 Example :
<t:out v="The agency city is @{agency.city,NO CITY}"/>

Telosys framework - Symbolic variables ( Laurent Guérin ) 7

Symbolic variables for Java beans


 Bean search order :
 When a bean is specified by a name
( e.g. @{agency.code} ), the name is searched in the
following scopes order :
 1 – screen-context data element ( Telosys ) (*)
 2 – screen-context attribute ( Telosys ) (*)

 3 – standard servlet request ( standard "request scope" )

 4 – screen-session ( Telosys )

 5 – standard http session (standard "session scope" )

 6 – screen-application ( Telosys )

 7 – standard servlet context (standard "application scope" )

(*) The screen-context is defined only in screen actions, not in a


service call

Telosys framework - Symbolic variables ( Laurent Guérin ) 8

Telosys 4
Symbolic variables and services
 Special bean name :
 "RENDERER-BEAN" ( or "RENDERER_BEAN" )
points the "service result" object
( this special name is usable only in a service renderer )
 Example :
Agency result = new Agency();
serviceResponse.setResult(result);

<t:out v="The agency city is @{RENDERER-BEAN.city}"/>

 Any other bean can be used in a classical way if


the service expose it in the request scope
Agency agency = new Agency();
serviceResponse.expose("agency", agency);

<t:out v="The agency city is @{agency.city}"/>

Telosys framework - Symbolic variables ( Laurent Guérin ) 9

Symbolic variables for List


 Size of a Collection, VOList or DataSet :
 @{mylist.size} list size

 Example ( list with a VOList ) :


<h4> <t:out v="@{MYLIST.size}" /> element(s) in the list : </h4>
<t:list id="agencies" width="700" >

<t:listbody data="MYLIST" height="240" indexbase="100" >


<t:listrow id="row@{#count}"
cl="row_@{#count-parity}" > <%-- cl="row_even" or "row_odd" --%>
<t:listcell > <t:out v="@{#count}"/> </t:listcell>
<t:listcell > <t:out v="@{#index}"/> </t:listcell>
<t:listcell > <t:out v="@{.code,,000}"/> </t:listcell>
<t:listcell > <t:out v="@{.name,???}"/> </t:listcell>
<t:listcell > <t:out v="@{.city,''}"/> </t:listcell>
<t:listcell > <t:out v="@{.phone,''}"/> </t:listcell>
</t:listrow >
</t:listbody >

</t:list>

Telosys framework - Symbolic variables ( Laurent Guérin ) 10

Telosys 5
Symbolic variables for DataSet
 DataSet cells can be accessed with a number
corresponding to the column number of the
current DataRow ( 1 to n ) :
 @{.1} or @{1} value of the column 1
 @{.2} or @{2} value of the column 2
 etc …
 Example ( list with a Dataset ) :
<t:listbody data="MYDATASET" height="240" indexbase="100" >
<t:listrow >
<t:listcell > <t:out v="@{#count}"/> </t:listcell>
<t:listcell > <t:out v="@{#index,??,'0000'}"/> </t:listcell>
<t:listcell > <t:out v="@{1,???}"/> </t:listcell>
<t:listcell > <t:out v="@{2,??,'000'}"/> </t:listcell>
<t:listcell > <t:out v="@{.3,??,'0000.00'}"/> </t:listcell>
<t:listcell > <t:out v="@{.4,??,'Yes|No'}"/> </t:listcell>
</t:listrow >
</t:listbody >

Telosys framework - Symbolic variables ( Laurent Guérin ) 11

Default value & format

Telosys 6
Symbolic variables - Default value
 If the symbolic variable is not found
 If there is a default value : it is used
 Else : a void string is returned ( "" )
 The default value is located at the 2nd position
examples :
 @{myint,123}  "123" if not found
 @{myint,123,000000}  "123" if not found
 @{mystr,'bla bla'}  "bla bla" if not found
 @{mystr,bla bla}  likewise (the quotes are optional)
 When the default value is used, it is returned
"as is", the format is not applied on a default value

Telosys framework - Symbolic variables ( Laurent Guérin ) 13

Symbolic variables - Format


 The format is located at the 3d position
examples :
 @{myint,,00000}  "00123" for 123
 @{myint,not found,000000}  likewise

 @{mydate,,'yyyy-MM-dd'}  "2008-03-30"
 @{mydate,,yyyy-MM-dd}  likewise
(the quotes are optional)
 Without format, the "toString" method of the
object is used
 The format is not applied on the default value

Telosys framework - Symbolic variables ( Laurent Guérin ) 14

Telosys 7
Symbolic variables - Format
 Boolean object format :
 Without format boolean returns "true" or "false"
 Format syntax : "value-if-true|value-if-false"
examples :
 @{mybool,,Yes|No}
 @{mybool,,Black|White}
 @{mybool,,1|0}
 Number object format
(Integer, Long, Double, BigDecimal, BigInteger, … )
 If the format contains "|"
See
 the "java.text.ChoiceFormat" is used
the
 Else java
 the "java.text.DecimalFormat" is used doc
 Date object format
 The "java.text.SimpleDateFormat" is used
Telosys framework - Symbolic variables ( Laurent Guérin ) 15

Use cases

Telosys 8
Use cases
 Print a bean attributes :
<table>
<tr><td>Code</td><td><t:out v="code @{agency1.code,,'c000'}" /></td></tr>
<tr><td>Name</td><td><t:out v="name @{agency1.name}" /> </td></tr>
<tr><td>City</td><td><t:out v="city @{agency1.city,NO CITY}"/> </td></tr>
</table>

 Using "with/without" tag :


<t:with bean="agency1" scope="request" >
<table border="1">
<tr> <td> <t:out v="Code = @{.code}" /> </td> </tr>
<tr> <td> <t:out v="Name = @{.name}" /> </td> </tr>
<tr> <td> <t:out v="City = @{.city}" /> </td> </tr>
</table>
</t:with>
<t:without bean="agency1" scope="request" >
<h2>Bean not found</h2>
</t:without>

Telosys framework - Symbolic variables ( Laurent Guérin ) 17

Use cases
 Iterate on a list :
<table>
<t:iterate list="mylist" scope="session" indexbase="100" >
<tr>
<td> <t:out v="@{#count,,000}" /> </td>
<td> <t:out v="@{#index,,'idx-00'}" /> </td>
<td> <t:out v="@{.code,???,000}" /> </td>
<td> <t:out v="@{.city,'no city'}" /> </td>
<td> <t:out v="@{.phone,'???'}" /> </td>
</tr>
</t:iterate>
</table>

Telosys framework - Symbolic variables ( Laurent Guérin ) 18

Telosys 9
Use cases
 Populate combo box items from a list of beans :
<t:combobox id="ag1" x="80" y="40" value="2" >
<t:comboitems list="mylist" id="agency_item" cl="myclass"
style="color:red" title="The title @{#count}"
value="@{.code}"
txt="@{.code} - @{.name} (@{#count})(@{#index})"/>
</t:combobox>

 Populate combo box items from a DataSet :


<t:combobox id="Ag999" x="80" y="40" value="003" >
<t:comboitems list="MYDATASET" style="color:@{3,black}"
value="@{.2,000,'000'}"
txt="@{.2,000,'000'} - @{.1,???} (@{#count})(@{#index})"/>
</t:combobox>

 It's the same for list box,


with tags <t:listbox … > and <t:listitems ..>

Telosys framework - Symbolic variables ( Laurent Guérin ) 19

THE END

Telosys 10

You might also like