Wednesday, November 13, 2013

JSTL Example


<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page isELIgnored ="false" %>

<table>
<tr>
    <th>UserId</th>
    <th>Name</th>
</tr>
    <c:forEach var="user" items="${ALLUSERLIST}">
    <tr>
        <td><c:out value="${user.userId}"/></td>
        <td><c:out value="${user.personName}"/></td>
    </tr>
</c:forEach>
</table>

<c:set var="salary" scope="session" value="${2000*2}"/>
<c:if test="${salary > 2000}">
   <p>My salary is: <c:out value="${salary}"/><p>
</c:if>

===============
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>
================

Javascript Collection

Best Practices:  JavaScript should be at declared right before the closing body tag.
If script uses document.write to insert part of the page's content, it can't be moved lower in the page.
========================
onsubmit="return !!(ValidateEmail(document.PREMIUM_FORM.email) & ValidatePhone(document.PREMIUM_FORM.phone) )"
========================
function ValidateName(inputtxt)
{
    if(inputtxt.value=="")
    {
        alert("Please Enter Your Name");
        return false;
    }
    return true
}
========================
function ValidatePhone(inputtxt)
{
var phoneno = /^\d{10}$/;  

  var phoneno = /^\d{10}$/;
  if(inputtxt.value.match(phoneno))
     {
       return true;
     }
   else
     {
       alert("Please provide a valid Phone Number");
       return false;
     }
}
========================
function ValidateEmail(email)
{
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(email.value)) {
        alert("Please provide a valid email address");
    return false;
    }
    return true
}
========================
Example:
sample-javascript-registration
========================