110 likes | 292 Views
Symbolic Variables. Laurent Guérin / v 0.9.9 / 2008 - April. 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 :
E N D
Symbolic Variables Laurent Guérin / v 0.9.9 / 2008 - April
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 )
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 :value txt title zone cl style disabled readonly Telosys framework - Symbolic variables ( Laurent Guérin )
Symbolic variables : predefined values • Predefined names ( starting with "#" ) : • @{#count} the current count value in iterations from 1 to n • @{#index} the current index value in iterations from index-base (0 by default) to n • @{#session-id} the current session id • @{#user-login} the current user login • @{#user-language} the current user language • @{#user-role} the current user role Telosys framework - Symbolic variables ( Laurent Guérin )
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 )
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 ( 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 )
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 )
Use cases • Print a bean attributes : • Using "with/without" tag : <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> <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 )
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 )
Use cases • Populate combo box items from a list of beans : • Populate combo box items from a DataSet : • It's the same for list box, with tags <t:listbox … > and <t:listitems ..> <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> <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> Telosys framework - Symbolic variables ( Laurent Guérin )