Just another site

refresh maven after adding lib to your local repository

Failure to find aa:bb-plugin:jar:0.3 in was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
I got this error when I add lib to my local repository manually and try to build the project. I had to run “mvn validate” to refresh the repository and then it starts working.


Mysql case statement

Output string depending on the column value:

select email,
CASE language_id WHEN 0 THEN 'English'
WHEN 1 THEN 'Japanese'
ELSE 'Unknown'
END as Language
from tgf_mobileuser
where email is not null;

print css example

I had a task to print a dashboard page.  The print review looks quite different from the web page, so I have to create a print css to customize the display.

Create a print link on the page to call the below function.

		function printDiv() {					    
                     //backup dom
		     var originalContents = document.body.innerHTML;
                     //make whatever change you want, remove unnecessary elements	
                     //print the modified page

                     //reset page 	
	             document.body.innerHTML = originalContents;

Include the css on the page,  apply the page break only in print mode.

@media all {
	.page-break {
		display: none !important;

@media print {
	html, body, ul {
		float: none !important;
	.page-break {
		display: block;
		page-break-after: always;


POI add number cell

Make sure you add cell value as number, otherwise you can’t sort the columns in new file.

Add number:

HSSFRow row = sheet.createRow(sheet.getLastRowNum());
HSSFCell cell = row.createCell(0);
HSSFCellStyle style = workbook.createCellStyle();

Add percentage:

cell.setCellValue(0.123); // set value as number
CellStyle style = workbook.createCellStyle();


Hibernate exception: duplicate association path

Hibernate doesn’t provide function to check existing alias. If you try to add the same alias to the criteria, you will get exception: duplicate association path.

The solution is to create a set and record all exisitng alias. We only add new alias if it’s not in the set.

private List<String> aliasValues = new ArrayList<>();

Javascript drawing on an image inside a canvas

I just finished a task: load an image inside a popup canvas then draw lines on the canvas and save the image data. I had a couple issues during the development, but luckily I managed to find answers on google.

  1. How to draw on canvas on mobile devices.
    I found a good article which give all the details Using Touch Events with the HTML5 Canvas.  You should be aware of the difference code for IOS,Android and canvas in browser. The touch devices use “touchmove”,”touchstart” while the browswer uses “mousemove”,”mousedown”..etc
  2. We need to stop page scrolling when user are ready for drawing.
    stopScroll = (ev) ->
    $page.on("popupbeforeposition","#popupPanel", (event,ui) ->
    $page.on("popupafterclose","#popupPanel",(event,ui) ->
  3. How to improve image quality.
    When loading the photo to canvas, you may get a blurry image. The following code improve the quality of image

    canvastx = popupCanvas.getContext("2d");
    canvastx.webkitImageSmoothingEnabled = false;
    canvastx.mozImageSmoothingEnabled = false;
    canvastx.imageSmoothingEnabled = false;
  4. Don’t resize canvas, you should always create new one.
    Make sure you create new canvas after reading the image info. This way you know the image demision, then you could create new canvas with the same width/height ratio.  If you draw on a resized canvas,  everything(x,y point) on that canvas will be scaled.  You will have to do some calculation to get the orginal point. That’s why I prefer creating a new canvas with the right size.

Endless loop with ListIterator .hasNext()

The following code will create an endless loop because java creates new iterator everytime you call list.iterator():


We should do it this way:

Iterator iterator = someList.iterator();

POI read cell value as string

When you get error for reading cell value as string:

Cannot get a numeric value from a text cell
or Cannot get a boolean value from a text cell

The code below will format the cell properly and return string value:

final DataFormatter df = new DataFormatter();
final XSSFCell cell = row.getCell(cellIndex);
String valueAsString = df.formatCellValue(cell);

Request URI too long

I had a task to add a link in a chart. Depends on the area user clicks,  the system will create a get request, forward the user to next page.  The URL looks like “http://localhost:8080/nextpage?q=para1:1,2,3,4;para2:3,2,2,3;para3:test1,test2,test..”. The URL becomes too long and gives an error in the browser: request URI too long.

All we need to do is to change the request to post request. We create a hidden form on the page, which contains one input field and one button. the input field is used to save the parameters value (q in the example), and when user click the chart. I set the parameters value to the input field, then trigger a click on the button to submit the form.

And the code in javascript listener:


Jquery mobile multiple select with many options

When multiple select has too many options, jquery mobile will open a dialog rather than popup, which is a new page. Every time the popup is closed the pagecontainerbeforeload and pagecontainershow events are triggered again and thereby the initialisation code. We could add a check on the prevPage to avoid unwanted initialisation.

    $(document).on( "pagecontainerbeforeload", function( event, data ) {
         ......initialisation code....