Tuesday, July 17, 2012

Upload a file in a single click using jQuery as in gmail attachement

In older days, user wants to browse the button, choose the file and click the upload button for attaching the file.

Nowadays user does not like more mouse click operation. They all are would like to perform all operations within a single click.

The following jquery script is used to upload a file in single click.


<a id='uploader' href='javascript:void(0)'>Add Attachment</a>

   upclick(
     {
      element: uploader,
      action: '/file/fileUpload.action?method=fileUpload,
      dataname:'upload',
      oncomplete:
        function(response_data)
        {
            alert('Data has been sent successfully');
        }
     });
 }


* note: Have to include the attached js file

Monday, July 16, 2012

Problem in compiling and installing a simple maven project

While running “mvn install” We may receive the following error:

Error installing artifact's metadata: Error installing metadata:
Error updating group repository metadata
input contained no data


Reason:


      The problem here was an empty/corrupted maven-metadata-local.xml in our local repository of the artifact wanted to install.


Solution:

   Find the maven-metadata-local.xml using below given command

   sudo find / -name maven-metadata-local.xml -empty -print


   Remove the file maven-metadata-local.xml from that location and run "mvn install". This will work perfectly.

Wednesday, July 4, 2012

Move the Screen to next page by swiping on screen Using jQuery touch Swipe: iPad/iPhone


    The screen is designed by jquery will be used in iPad and iPhone applications.
If we use click event in iPad/iPhone, It will look ugly.It might not give the iPad application feel.
This post will help us to implement the swipe feature iPad using jquery touch swipe.

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%
String contextPath = request.getContextPath();
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="/13339/patientportal/jquery.touchSwipe.js"></script>
<title><tiles:insertAttribute name="title" ignore="true" /></title>
</head>
<script>
var ua = navigator.userAgent;
var isiPad = /iPad/i.test(ua) || /iPhone OS 3_1_2/i.test(ua) || /iPhone OS 3_2_2/i.test(ua);
//if(isiPad){
var swipeOptions=
{
swipe:swipe,
threshold:0
}
$(function()
{
//Enable swiping...
$("#commonprofile").swipe( swipeOptions );
});
//}
//Swipe handlers.
//The only arg passed is the original touch event object
function swipe(event, direction)
{
var tc = document.getElementById("tabs");
var ary = tc ? tc.getElementsByTagName("a") : [];
var id = $("li.active").attr("id");
if(direction=='left' && id < 5){
id++;
var url = ary[id].href.split("4080");
window.location.href = url[1];
}else if(direction=='right' && id > 0){
id--;
var url = ary[id].href.split("4080");
window.location.href = url[1];
}
}
</script>
<body style="background-color:#323232;margin:0px">
<div id="tabs" class="tab">
<ul class="tabs">
<li id="0" class="active"><a href="/patientportal/profileDetails.action"
style="color: #0B5D95;">Profile</a></li>
<li id="1" ><a href="/patientportal/patientClinicalDetails.action">Clinical</a>
</li>
<li id="2"><a href="/patientportal/patientMedicalDetails.action">Medication</a>
</li>
<li id="3"><a href="/patientportal/patientInvestigationDetails.action">Lab Result</a></li>
<li id="4"><a href="/patientportal/patientAllergyDetails.action">Allergies</a>
</li>
</ul>
<div id="commonprofile">
<div id="profile" align="left" class="tab_container"><%= request.getAttribute("treatmentSummaryProfile") %>
</div>
</div>
</div>
</body>
</html>


Download Path:
   You can down load the jquery.touchSwipe.js from below given url.
     https://github.com/mattbryson/TouchSwipe-Jquery-Plugin
If you add, above downloaded file the scrolling and zooming will not work.
you have to modify the below given changes.

    1. Open the downloaded js file.
    2. Search for the function init(options)  and
    3.  Replace

     if (options && (options.allowPageScroll==undefined && (options.swipe!=undefined || options.swipeStatus!=undefined)))
            options.allowPageScroll=NONE;

 by
    if (options)
            options.allowPageScroll=AUTO;

   

Monday, July 2, 2012

Sample Java Program for Implementing Singleton.


package com.test;

public class MainTest {
public static void main(String[] args) {
SingletonsTest test = SingletonsTest.getInstance();
SingletonsTest test2 = SingletonsTest.getInstance();
// SingletonTest tss = new SingletonTest();
}
}

class SingletonsTest{
private static SingletonsTest uniqTest;
private SingletonsTest(){
}
public static synchronized SingletonsTest getInstance(){
if(uniqTest == null){
System.out.println("New instances are created====");
uniqTest = new SingletonsTest();
}
return uniqTest;
}
}

Multiple row insert in sql server from java


We can insert the multiple rows into sql server from java using the statement.executeBatch()
function. The sample program for inserting the multiple rows are given below.

package com.test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class MultipleRowUpdateTest {
public static void main(String[] args) {
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/portal","root", "root");
Statement stmt = conn.createStatement();
stmt.addBatch("INSERT INTO role " +
"VALUES(5,'temp5','ROLE_ESWAR5')");
stmt.addBatch("INSERT INTO role " +
"VALUES(6, 'temp3','ROLE_ESWAR2')");
stmt.addBatch("INSERT INTO role " +
"VALUES(7, 'temp4','ROLE_ESWAR3')");
stmt.executeBatch();
}catch (Exception e) {
e.printStackTrace();
}
}
}