Showing posts with label JSP. Show all posts
Showing posts with label JSP. Show all posts

Tuesday, April 23, 2013

Custom JSP tags

1) Make sure that the library for tags is in your classpath. servlet-api-2.3.jar supports it.
2) Create the tag class
   Ex.
   public class MyTag extends TagSupport
   public class HelloTag extends SimpleTagSupport
3) Create the tag libray descripto file and put anywhere inside WEB-INF directory
   Ex. WEB-INF/tld/myApp.tld
<taglib>
  <tlib-version>1.0</tlib-version>
  <jsp-version>2.0</jsp-version>
  <short-name>Example TLD</short-name>
  <tag>
    <name>Hello</name>
    <tag-class>com.tutorialspoint.HelloTag</tag-class>
    <body-content>empty</body-content>
  </tag>
</taglib>
4) Use the tag. You can also set uri in tld and use it as your uri in JSP page.
<%@ taglib prefix="ex" uri="WEB-INF/tld/myApp.tld"%>
<html>
  <head>
    <title>A sample custom tag</title>
  </head>
  <body>
    <ex:Hello message="This is custom tag" />
  </body>
</html>

Sunday, September 12, 2010

JSP / JSTL / EL

JSP
JavaServer Pages (JSP) - is the standard presentation-layer technology for the J2EE platform.

JSP scripting elements:
  • expressions
    - form: <%= javaExpression %>
    - ex: date = <%= new java.util.Date() %>
    - xml syntax: <jsp:expression>javaExpression</jsp:expression>
  • scriptlets
    - form: <% code %>
    - xml syntax: <jsp:scriplet>code</jsp:scriplet>
  • declarations
    - form: <!% code %>
    - xml syntax: <jsp:declaration>code</jsp:declaration>
Comments
  • JSP Comment - <%-- JSP Comment --%>
  • HTML Comment - <!-- HTML Comment -->
Predefined vars: request, response, session, out, application, config, pageContext and page

JSTL

JSP Standard Tag Library (JSTL) - is a collection of standard custom tag libraries that implement basic functionality common to a wide range of server-side Java applications.

EL
Expression Language (EL) - is a simplified form for JSP expression
- syntax: ${elExpression}

Source:
http://www.ibm.com/developerworks/java/library/j-jstl0211.html
http://download.oracle.com/docs/cd/E17802_01/j2ee/j2ee/1.4/docs/tutorial-update2/doc/index.html

Monday, February 16, 2009

JSP Pointers

  • secure/nonsecure alerts on IE6 & 7
  • http://www.zorked.com/security/ie-mixed-content-secure-nonsecure-items/

  • no caching on browsers
  • add: (remove space b/w < and META)
      
    < META HTTP-EQUIV="Expires" CONTENT="0"> - any # less than 1 means no cache
    < META HTTP-EQUIV="Pragma" CONTENT="no-cache"> - for backward compatability
    < META HTTP-EQUIV="Cache-Control" CONTENT="no-cache"> - for HTTP 1.1 spec  

  • day in Date
  • function fnGetPrevDayDate(objDate){
     // 1 day = 86400000 ms 
     // var datPrevDate = new Date(objDate.getTime() - 86400000);
     // code above returns incorrect result when time changes from DST to standard time
     
     var datPrevDate = new Date(objDate);
     datPrevDate.setDate(datPrevDate.getDate() - 1);
     return datPrevDate;
    }

  • html:checkbox
  • -If the form is in session and you change the checkbox from true(checked) to false(unchecked), the checkbox attribute in form is not set back to false. This is because the unchecked checkbox is not sent in the request and is therefore not set in the form.
    -solution: Add a reset method in form & reset checkbox to false. Everytime you submit the form, form is reset and then populated before moving to action, thus having correct value for the checkbox.

  • how to use indexId on logic:iterate
  • < logic:iterate id="entityRow" name="<%= DerivativeEntityConstantsIF.SEARCH_RESULT %>" scope="session" offset="<%= String.valueOf(offset)%>" length="<%= String.valueOf(maxLength)%>" indexId="indexNum">
      < html:select name="entityRow" property="linkageClassCode"
    onchange='<%= "fnEditValue(this, " + indexNum + ")" %>' >...

  • html element default values - defaultValue/defaultSelectedd
  • if (frm["termDeal.accountNo"].value != frm["termDeal.accountNo"].defaultValue) return true;
    if (fnIsSelectChanged(frm["termDeal.currency"])) return true;
    
    function fnIsSelectChanged(selectObj) {
      var index = selectObj.selectedIndex;
      var selectedOption = selectObj.options[index];
      if (selectedOption.defaultSelected) return false; 
      return true;
    }

  • use popUpCalendar.js
  • if (!document.layers){
    var startDate = document.getElementById("personalInfoForm.dateOfBirth");
    // use showCalendarWithHolidays if you want to show holidays
    document.write("<[toRemove]a href='javascript:void(0)' onclick='showCalendarWithHolidays(this, startDate, \"mm-dd-yyyy\",null,1,-1,-1, true)'><[toRemove]img src='' border='0'/>");
    }

  • regex of replace
  • .value.replace(/_|-/g, '')  --> replace _ and - with empty str

  • use of sessionScope
  • CL.isNewClient = ${sessionScope[ClientConstants.IS_NEW_CLIENT]} --> do not put semi colon at end (not sure if for AMS only)