Wednesday, June 13, 2012

Table header is not fixed with Jquery fixheadertable plugin

If you load the table result into a div like the following, where you try to fix the height with css with overflow, the header will not be fixed after scrolling

     <div id="divA21InvResult" style="height:300px;overflow:auto"></div>  



Instead you should add the option "height" when you call the fixheadertable function and pair with a simple div without any height declaration in css

       <div id="divA21InvResult"></div>  

        $('#tblA21InvPrint').fixheadertable({
                    caption     : '',
                    height      : '300',                   
                    colratio    : [30, 50, 100, 100, 50, 515, 80, 400, 400],                  
                    sortable    : true,
                    sortedColId : 1,
                    dateFormat  : 'd-M-Y',
                    resizeCol   : true, 
                    sortType    : ['string1','integer', 'date', 'string', 'string', 'string', 'float', 'string', 'string'],
                    textAlign   : ['center','right','center','center','center','left','right','left','left']
                });


Tuesday, June 12, 2012

Error Placement Issue with Jquery Validation Plugin










I encountered the above problem with jquery validation plugin where the error message spans into multiple lines, eventhough there is more than enough span after the input element.

To solve this problem, you may add in the following css

label.error{
    color:red;   
    width:auto; /*Add this line*/
}


Saturday, January 28, 2012

How to embed fonts into PDF generated by JasperReport (iReport)

Setup:
» Tomcat 7.0 + JSP
» iReport 4.1.1

Reference:
http://javaskeleton.blogspot.com/2010/12/embedding-fonts-into-pdf-generated-by.html

Steps:
1. Launch iReport, choose Tools->Options->Fonts

2. Click "Install Font" and follow the wizard to install your desired font.



*Remember to tick the option "Embed this font in the PDF document"








3. Select the newly installed font and click the button "Export as extension"




4. Save the export file as JAR file

5. Copy the JAR file to the folder within your application classpath
*I choose to put all the JAR files into $(JRE_HOME}/lib/ext

Friday, January 13, 2012

How to display/Store Chinese Character Thru Browser

The following is extracted from http://java.sun.com/developer/technicalArticles/Intl/HTTPCharset/#browser

Server: Tomcat
1. Setting the context parameter is done in the WEB-INF/web.xml file.

<context-param>
<param-name>PARAMETER_ENCODING</param-name>
<param-value>UTF-8</param-value>
</context-param>

2. Add the following code to your JSP file.
<%
    //Must put in the first section of the jsp page
    String paramEncoding = application.getInitParameter("PARAMETER_ENCODING");
    request.setCharacterEncoding(paramEncoding); 

%>
*Please note that the following lines must be inserted at the begining of the JSP page after header declaration (eg. tagLib or Page), before any other content processing.

Friday, January 6, 2012

Run JasperReport (ireport) in JSP

(1) Import the following libraries to your project
===================================================
jasperreports-3.7.2.jar
iText-2.1.7.jar
jdt-compiler-3.1.1.jar
groovy-all-1.5.5.jar
commons-logging-api-1.1.jar
commons-logging-adapters-1.1.jar
commons-logging-1.1.jar
commons-digester-1.8.jar
commons-collections-testframework-3.2.jar
commons-collections-3.2.jar
commons-beanutils-core.jar
commons-beanutils-bean-collections.jar
commons-beanutils.jar

(2) Sample JSP Code
===================================================
String dirPath = "ireports";
String realPath = this.getServletContext().getRealPath(dirPath);
String orderNo = request.getParameter("orderNo");
String jasperReport = "nameCardFront.jasper";
JasperPrint print = null;
String outputFileName = null;
Connection conn = null;

try{
InitialContext initialContext = new InitialContext();
DataSource ds = (DataSource)initialContext.lookup("java:comp/env/jdbc/DOS");
conn = ds.getConnection();

Map parameters = new HashMap();
parameters.put("orderNo", "a");
print = JasperFillManager.fillReport(realPath + "//" + jasperReport, parameters, conn);

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss");
outputFileName = "file.pdf";

out.clearBuffer();
//set the content type(can be excel/word/powerpoint etc..)
response.setContentType ("application/pdf");
//set the header and also the Name by which user will be prompted to save
response.setHeader ("Content-Disposition", "attachment; filename=\"" + outputFileName);

JasperExportManager.exportReportToPdfStream(print, response.getOutputStream());

}
catch(Exception ex){
ex.printStackTrace();
out.println(ex.getMessage());
}
finally{
if (conn != null)
conn.close();
}

Monday, August 16, 2010

Netbeans 6.8 with Tomcat 6.0.20 - Requires JDK 6 Update 20

Netbeans 6.8 + Tomcat 6.0.20

Tested worked with JDK 6 Update 20

JDK 6 Update 19, JDK 6 Update 21 failed to work

Error:
In any jsp file, Netbeans will highligh error for the following lines

<%@ page contentType="text/html" session="true" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

*Courtesy of Andy Lim*

Friday, March 12, 2010

给宠物狗的鞋子 : 一双/两双?

周五,吃了晚饭和同事到新开的宠物店闲逛。一边赞叹琳琅满目的宠物食/用品,同事指了指包装精美的四只宠物狗鞋子。

下意识的,我回应说“不错哦,有两双可以替换”。。。。

“两双?”,同事楞了楞说道。

我说“对啊,四只不就两双吗?”。。。。

“狗有四只脚。。。。”

哈哈,惯性思维。总想着人就一双两只鞋呗,所以见到四只鞋子就理所当然的以为是两双,还“替换”呢!

其实日常工作中,常有因为惯性思维而闹笑话的事,很多时候当事人并不知晓犯了什么错误,就像我一样,愣是得意着。

注:请不要咬文嚼字计较四只,该说是一套/一双/两双?重点在于“替换” 与 “惯性思维”