Your Ad Here

Sunday, June 29, 2008

Simple JavaScript Clock

Simple JavaScript Clock

<SCRIPT Language="JavaScript">

<!-- hide from old browsers

function jsClock(){

var time = new Date()

var hour = time.getHours()

var minute = time.getMinutes()

var second = time.getSeconds()

var temp = "" + ((hour > 12) ? hour - 12 : hour)

if(hour==0) temp = "12"

if(temp.length==1) temp = " " + temp

temp += ((minute < 10) ? ":0" : ":") + minute

temp += ((second < 10) ? ":0" : ":") + second

temp += (hour >= 12) ? " PM" : " AM"

document.clockForm.digits.value = temp

id = setTimeout("jsClock()",1000)

}

//-->

</SCRIPT>

<BODY ONLOAD="jsClock()">

<FORM NAME="clockForm">

<FONT face="Courier New,Courier" size=3><B>

<INPUT TYPE="text" NAME="digits" SIZE=11 VALUE="Loading"></B>

</FONT>

</FORM>

Javascript Time functions

The Date object has been created and now we have a variable that holds the current date. To get the information we need to print out the date we have to utilize some or all of the following functions:

  • getTime() - Number of milliseconds since 1/1/1970 @ 12:00 AM
  • getSeconds() - Number of seconds (0-59)
  • getMinutes() - Number of minutes (0-59)
  • getHours() - Number of hours (0-23)
  • getDay() - Day of the week(0-6). 0 = Sunday, … , 6 = Saturday
  • getDate() - Day of the month (0-31)
  • getMonth() - Number of month (0-11)
  • getFullYear() - The four digit year (1970-9999)

Today's Date

<!– hide from old browsers
document.write(getDateStr())
//–>
June 19, 2008

 
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
  function GetMonth(intMonth){
    var MonthArray = new Array("January", "February", "March",
                               "April", "May", "June",
                               "July", "August", "September",
                               "October", "November", "December")
    return MonthArray[intMonth]
    }
  function getDateStr(){
    var today = new Date()
    var year = today.getYear()
    if(year<1000) year+=1900
    var todayStr = GetMonth(today.getMonth()) + " " + today.getDate()
    todayStr += ", " + year
    return todayStr
    }
//–>
</SCRIPT>

 
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
    document.write(getDateStr())
//-->
</SCRIPT>

Today's Date including day of week

<!– hide from old browsers
document.write(getDateStrWithDOW())
//–>
Thursday, June 19, 2008

 
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
  function GetDay(intDay){
    var DayArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
                         "Thursday", "Friday", "Saturday")
    return DayArray[intDay]
    }
 
  function GetMonth(intMonth){
    var MonthArray = new Array("January", "February", "March",
                               "April", "May", "June",
                               "July", "August", "September",
                               "October", "November", "December")
    return MonthArray[intMonth]
    }
  function getDateStrWithDOW(){
    var today = new Date()
    var year = today.getYear()
    if(year<1000) year+=1900
    var todayStr = GetDay(today.getDay()) + ", "
    todayStr += GetMonth(today.getMonth()) + " " + today.getDate()
    todayStr += ", " + year
    return todayStr
    }
//–>
</SCRIPT>

 
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
    document.write(getDateStrWithDOW())
//-->
</SCRIPT>

Todays Date (short format)

<!– hide from old browsers
var today = new Date()
var year = today.getYear()
if(year<1000) year+=1900

document.write((today.getMonth()+1) + "/" +
today.getDate() + "/" + (year+"").substring(2,4))
//–>
6/19/08

 
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
  var today = new Date()
  var year = today.getYear()
  if(year<1000) year+=1900
 
  document.write((today.getMonth()+1) + "/" +
                  today.getDate() + "/" + (year+"").substring(2,4))
//-->
</SCRIPT>

Todays Date (short format, full year)

<!– hide from old browsers
var today = new Date()
var year = today.getYear()
if(year<1000) year+=1900

document.write((today.getMonth()+1) + "/" +
today.getDate() + "/" + year)
//–>
6/19/2008

 
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
  var today = new Date()
  var year = today.getYear()
  if(year<1000) year+=1900
 
  document.write((today.getMonth()+1) + "/" +
                  today.getDate() + "/" + year)
//-->
</SCRIPT>

Todays Date (short format, leading zeros)

<!– hide from old browsers
var today = new Date()
var month = today.getMonth()+1
var year = today.getYear()
var day = today.getDate()
if(day<10) day = "0″ + day
if(month<10) month= "0″ + month
if(year<1000) year+=1900

document.write(month + "/" + day +
"/" + (year+"").substring(2,4))
//–>
06/19/08

 
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
  var today = new Date()
  var month = today.getMonth()+1
  var year = today.getYear()
  var day = today.getDate()
  if(day<10) day = "0" + day
  if(month<10) month= "0" + month
  if(year<1000) year+=1900
 
  document.write(month + "/" + day +
                 "/" + (year+"").substring(2,4))
//-->
</SCRIPT>

Todays Date (short format, leading zeros, full year)

<!– hide from old browsers
var today = new Date()
var month = today.getMonth()+1
var year = today.getYear()
var day = today.getDate()
if(day<10) day = "0″ + day
if(month<10) month= "0″ + month
if(year<1000) year+=1900

document.write(month + "/" + day +
"/" + year)
//–>
06/19/2008

 
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
  var today = new Date()
  var month = today.getMonth()+1
  var year = today.getYear()
  var day = today.getDate()
  if(day<10) day = "0" + day
  if(month<10) month= "0" + month
  if(year<1000) year+=1900
 
  document.write(month + "/" + day +
                 "/" + year)
//-->
</SCRIPT>

Todays Date (European format)

<!– hide from old browsers
var today = new Date()
var year = today.getYear()
if(year<1000) year+=1900

document.write(today.getDate() + "." +
(today.getMonth()+1) + "." + (year+"").substring(2,4))
//–>
19.6.08

 
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
  var today = new Date()
  var year = today.getYear()
  if(year<1000) year+=1900
 
  document.write(today.getDate() + "." +
                 (today.getMonth()+1) + "." + (year+"").substring(2,4))
//-->
</SCRIPT>

Basic Date and Time

<!– hide from old browsers
var curDateTime = new Date()
document.write(curDateTime)
//–>
Thu Jun 19 2008 12:02:04 GMT+0530 (India Standard Time)

 
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
  var curDateTime = new Date()
  document.write(curDateTime)
//-->
</SCRIPT>

Date and Time (24-hr format)

<!– hide from old browsers
var curDateTime = new Date()
document.write(curDateTime.toLocaleString())
//–>
Thursday, 19 June, 2008 12:02

 
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
  var curDateTime = new Date()
  document.write(curDateTime.toLocaleString())
//-->
</SCRIPT>

Basic GMT Date and Time

<!– hide from old browsers
var curDateTime = new Date()
document.write(curDateTime.toGMTString())
//–>
Thu, 19 Jun 2008 06:32:04 GMT

 
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
  var curDateTime = new Date()
  document.write(curDateTime.toGMTString())
//-->
</SCRIPT>

Time in 12-hr format

<!– hide from old browsers
var curDateTime = new Date()
var curHour = curDateTime.getHours()
var curMin = curDateTime.getMinutes()
var curSec = curDateTime.getSeconds()
var curAMPM = " AM"
var curTime = ""
if (curHour >= 12){
curHour -= 12
curAMPM = " PM"
}
if (curHour == 0) curHour = 12
curTime = curHour + ":"
+ ((curMin < 10) ? "0″ : "") + curMin + ":"
+ ((curSec < 10) ? "0″ : "") + curSec
+ curAMPM
document.write(curTime)
//–>
12:02:04 PM

 
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
  var curDateTime = new Date()
  var curHour = curDateTime.getHours()
  var curMin = curDateTime.getMinutes()
  var curSec = curDateTime.getSeconds()
  var curAMPM = " AM"
  var curTime = ""
  if (curHour >= 12){
    curHour -= 12
    curAMPM = " PM"
    }
  if (curHour == 0) curHour = 12
  curTime = curHour + ":"
    + ((curMin < 10) ? "0" : "") + curMin + ":"
    + ((curSec < 10) ? "0" : "") + curSec
    + curAMPM
  document.write(curTime)
//-->
</SCRIPT>

Time in 24-hr format

<!– hide from old browsers
var curDateTime = new Date()
var curHour = curDateTime.getHours()
var curMin = curDateTime.getMinutes()
var curSec = curDateTime.getSeconds()
var curTime =
((curHour < 10) ? "0″ : "") + curHour + ":"
+ ((curMin < 10) ? "0″ : "") + curMin + ":"
+ ((curSec < 10) ? "0″ : "") + curSec
document.write(curTime)
//–>
12:02:04

 
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
  var curDateTime = new Date()
  var curHour = curDateTime.getHours()
  var curMin = curDateTime.getMinutes()
  var curSec = curDateTime.getSeconds()
  var curTime =
    ((curHour < 10) ? "0" : "") + curHour + ":"
    + ((curMin < 10) ? "0" : "") + curMin + ":"
    + ((curSec < 10) ? "0" : "") + curSec
  document.write(curTime)
//-->
</SCRIPT>

Time for Specific Time Zone

<!– hide from old browsers
// Copyright 1999, 2000 by Ray Stott
// OK to use if this copyright is included
// Script available at http://www.crays.com/jsc
var TimezoneOffset = -8 // adjust for time zone
var localTime = new Date()
var ms = localTime.getTime()
+ (localTime.getTimezoneOffset() * 60000)
+ TimezoneOffset * 3600000
var time = new Date(ms)
var hour = time.getHours()
var minute = time.getMinutes()
var second = time.getSeconds()
var curTime = "" + ((hour > 12) ? hour - 12 : hour)
if(hour==0) curTime = "12″
curTime += ((minute < 10) ? ":0″ : ":") + minute
curTime += ((second < 10) ? ":0″ : ":") + second
curTime += (hour >= 12) ? " PM" : " AM"
document.write(curTime + " - US Pacific Time")
//–>
10:32:04 PM - US Pacific Time

 
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
  // Copyright 1999, 2000 by Ray Stott
  // OK to use if this copyright is included
  // Script available at http://www.crays.com/jsc
  var TimezoneOffset = -8  // adjust for time zone
  var localTime = new Date()
  var ms = localTime.getTime()
             + (localTime.getTimezoneOffset() * 60000)
             + TimezoneOffset * 3600000
  var time =  new Date(ms)
  var hour = time.getHours()
  var minute = time.getMinutes()
  var second = time.getSeconds()
  var curTime = "" + ((hour > 12) ? hour - 12 : hour)
  if(hour==0) curTime = "12"
  curTime += ((minute < 10) ? ":0" : ":") + minute
  curTime += ((second < 10) ? ":0" : ":") + second
  curTime += (hour >= 12) ? " PM" : " AM"
  document.write(curTime + " US Pacific Time")
//-->
</SCRIPT>

GMT Time

<!– hide from old browsers
var curDateTime = new Date()
var curHour = curDateTime.getHours()
+ curDateTime.getTimezoneOffset()/60
if (curHour > 24) curHour -= 24
if (curHour < 0) curHour += 24
var curMin = curDateTime.getMinutes()
var curSec = curDateTime.getSeconds()
var curTime =
((curHour < 10) ? "0″ : "") + curHour + ":"
+ ((curMin < 10) ? "0″ : "") + curMin + ":"
+ ((curSec < 10) ? "0″ : "") + curSec
document.write(curTime + " GMT")
//–>
06.5:02:04 GMT

 
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
  var curDateTime = new Date()
  var curHour = curDateTime.getHours()
     + curDateTime.getTimezoneOffset()/60
  if (curHour > 24)  curHour -= 24
  if (curHour < 0) curHour += 24
  var curMin = curDateTime.getMinutes()
  var curSec = curDateTime.getSeconds()
  var curTime =
    ((curHour < 10) ? "0" : "") + curHour + ":"
    + ((curMin < 10) ? "0" : "") + curMin + ":"
    + ((curSec < 10) ? "0" : "") + curSec
  document.write(curTime + " GMT")
//-->
</SCRIPT>

Offset from GMT

<!– hide from old browsers
var curDateTime = new Date()
document.write("GMT Offset for your time zone is ")
document.write(-(curDateTime.getTimezoneOffset()/60))
//–>
GMT Offset for your time zone is 5.5

 
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
  var curDateTime = new Date()
  document.write("GMT Offset for your time zone is ")
  document.write(-(curDateTime.getTimezoneOffset()/60))
//-->
</SCRIPT>

Days till Y3K

<!– hide from old browsers
var today = new Date()
var targetDate = new Date("01/01/3000″) //use full year
var timeBeforeTarget = Math.floor(( targetDate.getTime()
- today.getTime()) / 86400000)
var msg = "<B>There are only " + (timeBeforeTarget +1)
+ " days until the year 3000.</B>"
document.write(msg)
//–>
There are only 362151 days until the year 3000.

 
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
var today = new Date()
var targetDate = new Date("01/01/3000") //use full year
var timeBeforeTarget = Math.floor(( targetDate.getTime()
        - today.getTime()) / 86400000)
var msg = "<B>There are only "  + (timeBeforeTarget +1)
         + " days until the year 3000.</B>"
document.write(msg)
//-->
</SCRIPT>

Days after a Certain Date

<!– hide from old browsers
var today = new Date()
var targetDate = new Date("12/31/1999″) //use full year
var timeAfterTarget = Math.floor(( today.getTime()
- targetDate.getTime() ) / 86400000)
var msg = "This is day number " + timeAfterTarget + " for this year."
document.write(msg)
//–>
This is day number 3093 for this year.

 
<SCRIPT Language="JavaScript">
<!-- hide from old browsers
var today = new Date()
var targetDate = new Date("12/31/1999") //use full year
var timeAfterTarget = Math.floor(( today.getTime()
        - targetDate.getTime() ) / 86400000)
var msg = "This is day number " + timeAfterTarget + " for this year."
document.write(msg)
//-->
</SCRIPT>

Additional Information on These Scripts

All scripts are Y2K compliant.

The Basic Date and Time, Date and Time (24-hr format) and Basic GMT Date and Time are easy to implement but the results displayed will be different for different browsers and operating systems. All of the other scripts should display the same results for all browsers and operating systems.

The Time for a Specific Time Zone script can be set for any time zone by changing the TimeZoneOffset variable. If you don't know your time zone offset, you can find it out by using the Offset from GMT script. You may need to change this value twice a year to adjust for Daylight Savings Time.

Days till Y3K script can be used for other important dates by changing the date that is used to initialize the targetDate variable. Likewise, The Days after a Certain Date script can be used to count the days after a different date by changing the date that is used to initialize the targetDate variable. It is also important that you specify these dates with the full year, ie 2000 rather than 00, to be Y2K compliant.

Javascript Replace new Lines

var varNotes = varNotes.replace(
// Replace out the new line character.
new RegExp( “\\n“, “g” ),

// Put in … so we can see a visual representation of where
// the new line characters were replaced out.
“<br>”
);

configure CVS connection

How do I configure CVS connection settings?

  • You can specify connection settings in the Checkout wizard. Settings are persistently stored.

For example, to check out NetBeans sources, choose Versioning > Checkout (or Versioning > CVS > Checkout) from the main menu and use :pserver:anoncvs@cvs.netbeans.org:/cvs with empty password for anonymous checkout. Alternatively use your own NetBeans.org login and password instead of anoncvs.

  • Otherwise, the IDE uses automatic configuration detection (probing common cvs setup files). Open the Favorites window, and right-click to add and open an existing repository directory. If the cvs session fails, the IDE shows the connection configuration dialog so you can change the settings (e.g. configure a proxy).

Applies to: NetBeans 6.x, 5.x

Expression Language

Expression Language

A primary feature of JSP technology version 2.0 is its support for an expression language (EL). An expression language makes it possible to easily access application data stored in JavaBeans components. For example, the JSP expression language allows a page author to access a bean using simple syntax such as ${name} for a simple variable or ${name.foo.bar} for a nested property.

The test attribute of the following conditional tag is supplied with an EL expression that compares the number of items in the session-scoped bean named cart with 0:

<c:if test="${sessionScope.cart.numberOfItems > 0}"> 
  ...
</c:if> 

The JSP expression evaluator is responsible for handling EL expressions, which are enclosed by the ${ } characters and can include literals. Here's an example:

<c:if test="${bean1.a < 3}" >
  ...
</c:if> 

Any value that does not begin with ${ is treated as a literal and is parsed to the expected type using the PropertyEditor for the type:

<c:if test="true" >
...
</c:if> 

Literal values that contain the ${ characters must be escaped as follows:

<mytags:example attr1="an expression is ${'${'}true}" /> 

Deactivating Expression Evaluation

Because the pattern that identifies EL expressions--${ }--was not reserved in the JSP specifications before JSP 2.0, there may be applications where such a pattern is intended to pass through verbatim. To prevent the pattern from being evaluated, you can deactivate EL evaluation.

To deactivate the evaluation of EL expressions, you specify the isELIgnored attribute of the page directive:

<%@ page isELIgnored ="true|false" %> 

The valid values of this attribute are true and false. If it is true, EL expressions are ignored when they appear in static text or tag attributes. If it is false, EL expressions are evaluated by the container.

The default value varies depending on the version of the web application deployment descriptor. The default mode for JSP pages delivered using a Servlet 2.3 or earlier descriptor is to ignore EL expressions; this provides backward compatibility. The default mode for JSP pages delivered with a Servlet 2.4 descriptor is to evaluate EL expressions; this automatically provides the default that most applications want. You can also deactivate EL expression evaluation for a group of JSP pages (see Deactivating EL Expression Evaluation).

Using Expressions

EL expressions can be used:

  • In static text
  • In any standard or custom tag attribute that can accept an expression

The value of an expression in static text is computed and inserted into the current output. If the static text appears in a tag body, note that an expression will not be evaluated if the body is declared to be tagdependent (see body-content Attribute).

There are three ways to set a tag attribute value:

  • With a single expression construct:

<some:tag value="${expr}"/>

The expression is evaluated and the result is coerced to the attribute's expected type.

  • With one or more expressions separated or surrounded by text:

<some:tag value="some${expr}${expr}text${expr}"/>

The expressions are evaluated from left to right. Each expression is coerced to a String and then concatenated with any intervening text. The resulting String is then coerced to the attribute's expected type.

  • With text only:

<some:tag value="sometext"/>

In this case, the attribute's String value is coerced to the attribute's expected type.

Expressions used to set attribute values are evaluated in the context of an expected type. If the result of the expression evaluation does not match the expected type exactly, a type conversion will be performed. For example, the expression ${1.2E4} provided as the value of an attribute of type float will result in the following conversion:

Float.valueOf("1.2E4").floatValue()  

See section JSP2.8 of the JSP 2.0 specification for the complete type conversion rules.

Variables

The web container evaluates a variable that appears in an expression by looking up its value according to the behavior of PageContext.findAttribute(String). For example, when evaluating the expression ${product}, the container will look for product in the page, request, session, and application scopes and will return its value. If product is not found, null is returned. A variable that matches one of the implicit objects described in Implicit Objects will return that implicit object instead of the variable's value.

Properties of variables are accessed using the . operator and can be nested arbitrarily.

The JSP expression language unifies the treatment of the . and [] operators. expr-a.identifier-b is equivalent to expr-a["identifier-b"]; that is, the expression expr-b is used to construct a literal whose value is the identifier, and then the [] operator is used with that value.

To evaluate expr-a[expr-b], evaluate expr-a into value-a and evaluate expr-b into value-b. If either value-a or value-b is null, return null.

  • If value-a is a Map, return value-a.get(value-b). If !value-a.containsKey(value-b), then return null.
  • If value-a is a List or array, coerce value-b to int and return value-a.get(value-b) or Array.get(value-a, value-b), as appropriate. If the coercion couldn't be performed, an error is returned. If the get call returns an IndexOutOfBoundsException, null is returned. If the get call returns another exception, an error is returned.
  • If value-a is a JavaBeans object, coerce value-b to String. If value-b is a readable property of value-a, then return the result of a get call. If the get method throws an exception, an error is returned.

Implicit Objects

The JSP expression language defines a set of implicit objects:

In addition, several implicit objects are available that allow easy access to the following objects:

  • param: Maps a request parameter name to a single value
  • paramValues: Maps a request parameter name to an array of values
  • header: Maps a request header name to a single value
  • headerValues: Maps a request header name to an array of values
  • cookie: Maps a cookie name to a single cookie
  • initParam: Maps a context initialization parameter name to a single value

Finally, there are objects that allow access to the various scoped variables described in Using Scope Objects.

  • pageScope: Maps page-scoped variable names to their values
  • requestScope: Maps request-scoped variable names to their values
  • sessionScope: Maps session-scoped variable names to their values
  • applicationScope: Maps application-scoped variable names to their values

When an expression references one of these objects by name, the appropriate object is returned instead of the corresponding attribute. For example, ${pageContext} returns the PageContext object, even if there is an existing pageContext attribute containing some other value.

Literals

The JSP expression language defines the following literals:

  • Boolean: true and false
  • Integer: as in Java
  • Floating point: as in Java
  • String: with single and double quotes; " is escaped as \", ' is escaped as \', and \ is escaped as \\.
  • Null: null

Operators

In addition to the . and [] operators discussed in Variables, the JSP expression language provides the following operators:

  • Arithmetic: +, - (binary), *, / and div, % and mod, - (unary)
  • Logical: and, &&, or, ||, not, !
  • Relational: ==, eq, !=, ne, <, lt, >, gt, <=, ge, >=, le. Comparisons can be made against other values, or against boolean, string, integer, or floating point literals.
  • Empty: The empty operator is a prefix operation that can be used to determine whether a value is null or empty.
  • Conditional: A ? B : C. Evaluate B or C, depending on the result of the evaluation of A.

The precedence of operators highest to lowest, left to right is as follows:

  • [] .
  • () - Used to change the precedence of operators.
  • - (unary) not ! empty
  • * / div % mod
  • + - (binary)
  • < > <= >= lt gt le ge
  • == != eq ne
  • && and
  • || or
  • ? :

Reserved Words

The following words are reserved for the JSP expression language and should not be used as identifiers.

and   eq   gt   true   instanceof
or    ne   le   false  empty
not   lt   ge   null   div   mod 

Note that many of these words are not in the language now, but they may be in the future, so you should avoid using them.

Examples

Table 12-2 contains example EL expressions and the result of evaluating them.

Table 12-2 Example Expressions 

EL Expression

Result

${1 > (4/2)}

false

${4.0 >= 3}

true

${100.0 == 100}

true

${(10*10) ne 100}

false

${'a' < 'b'}

true

${'hip' gt 'hit'}

false

${4 > 3}

true

${1.2E4 + 1.4}

12001.4

${3 div 4}

0.75

${10 mod 4}

2

${empty param.Add}

True if the request parameter named Add is null or an empty string

${pageContext.request.contextPath}

The context path

${sessionScope.cart.numberOfItems}

The value of the numberOfItems property of the session-scoped attribute named cart

${param['mycom.productId']}

The value of the request parameter named mycom.productId

${header["host"]}

The host

${departments[deptName]}

The value of the entry named deptName in the departments map

${requestScope['javax.servlet.
forward.servlet_path']}

The value of the request-scoped attribute named javax.servlet.
forward.servlet_path

Functions

The JSP expression language allows you to define a function that can be invoked in an expression. Functions are defined using the same mechanisms as custom tags (See Using Custom Tags and Chapter 15).

Using Functions

Functions can appear in static text and tag attribute values.

To use a function in a JSP page, you use a taglib directive to import the tag library containing the function. Then you preface the function invocation with the prefix declared in the directive.

For example, the date example page index.jsp imports the /functions library and invokes the function equals in an expression:

<%@ taglib prefix="f" uri="/functions"%>
...
    <c:when
      test="${f:equals(selectedLocaleString,
        localeString)}" > 

Defining Functions

To define a function you program it as a public static method in a public class. The mypkg.MyLocales class in the date example defines a function that tests the equality of two Strings as follows:

package mypkg;
public class MyLocales {
 
  ...
  public static boolean equals( String l1, String l2 ) {
    return l1.equals(l2);
  }
} 

Then you map the function name as used in the EL expression to the defining class and function signature in a TLD. The following functions.tld file in the date example maps the equals function to the class containing the implementation of the function equals and the signature of the function:

<function>
  <name>equals</name>
  <function-class>mypkg.MyLocales</function-class>
  <function-signature>boolean equals( java.lang.String,
    java.lang.String )</function-signature>
</function> 

A tag library can have only one function element that has any given name element.

 

Your Ad Here
#chitikatest=doctor