Thursday, July 2, 2009
startsWith and endsWith functions in Javascript
var data = "Helloo Good Morning";
startsWith
String.prototype.startsWith = function(data)
{
return (this.match("^"+data)==data)
}
eg:
data.startsWith("Helloo");
returns true
-----------------------------------------------------------------------
endsWith
String.prototype.endsWith = function(data)
{
return (this.match(data+"$")==data)
}
eg:
data.endsWith("Helloo");
returns false;
----------------------------------------------------------
trim
String.prototype.trim = function()
{
return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""))
}
eg:
var tm = data.trim();
for more ...
http://www.tek-tips.com
Date showing wrong in JSF outputText or with dataTable
We can solve this problem using Converter.
One example :
DateConverter.java
package com.converter;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
/**
* This class is is used to convert a date to dd-MMM-yyyy format
* @author jijo
*
*/
public class DateConverter implements Converter {
public String getAsString(FacesContext context, UIComponent c, Object object)
throws ConverterException {
if(object!=null && !object.toString().equals("")){
final Date date = (Date) object;
String dt=null;
if(date!=null){
SimpleDateFormat formatter=new SimpleDateFormat("dd-MMM-yyyy");
dt=formatter.format(date);
return dt;
}}
return null;
}
public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2)
throws ConverterException {
return null;
}
}
In
faces-config.xml
<converter>
<converter-id>dateConvert<converter-id>
<converter-class>com.converter.DateConverter</converter-class>
</converter>
In your jsp page
<h:outputText value="#{item.onDate}" converter="dateConvert" />
Tuesday, June 23, 2009
Stream has already been closed; nested exception is java.sql.SQLException
Java - Oracle connectivity some times this exception will happen.
One of the reason of this exception is , the table contains a long(datatype) field.
eg: 'users' table contains a field 'age' long datatype.
To solve this problem , replace the 'long' field to 'number' datatype.
Tuesday, June 16, 2009
Check and Uncheck checkboxes using javascript
inside script tag
//this will mark all the checkboxes inside a form are checked.
//form1 is the form name
function checkAll() {
for(var i=0;i if(document.forms['form1'].elements[i].type=='checkbox') { document.forms['form1'].elements[i].checked=true; } } } //form1 is the form name function uncheckAll() { for(var i=0;i if(document.forms['form1'].elements[i].type=='checkbox') { document.forms['form1'].elements[i].checked=false; } } } ---------------------------------------------------------------------- //form1 -- formname //checkboxname-- checkbox name function selectAllFields() { var chk = document.form1.checkboxname; for (i = 0; i < checked =" true"> var chk = document.form1.checkboxname; for (i = 0; i }
//this will mark all the checkboxes inside a form are unchecked.
//form1 is the form name
//this will mark the specified checkboxes inside a form are checked
Monday, June 15, 2009
Drag and drop using using Javascript
More details check the following link,
http://developer.yahoo.com/yui/dragdrop/
Saturday, June 13, 2009
Deploy axis webservice in Jboss server
http://ws.apache.org/axis/java/install.html
Put the axis.war in jboss\server\default\deploy folder.
Then deploy the webservice in the axis.war and deploy the webservice using the command,
java org.apache.axis.client.AdminClient ..\src\com\jijo\stubs\deploy.wsdd
then copy the server-config.wsdd file from axis.war/WEB-INF folder and put the file in your WEB-INF folder.
In short first deploy in axis.war and copy the server-config.wsdd file and put into your project/WEB-INF folder.
WebService using Apache axis
axis.jar,axis-ant.jar,commons-discovery-0.2.jar,commons-logging-1.0.4.jar,jaxrpc.jar,
log4j-1.2.8.jar,saaj.jar,wsdl4j-1.5.1.jar.
Create one project eg: CalcTest and set classpath to theses jars.
Download the axis.war file from http://ws.apache.org/axis/java/install.html and put into your tomcat(webapps) or jboss(deploy) folder.
Create one interface
package com.jijo;
/**
* @author jijo
*
*/
public interface Calculator {
public int add(int x,int y);
public int subtract(int x, int y);
}
Create one class and implemet the Calculator interface
package com.jijo;
public class CalculatorImpl implements Calculator {
public int add(int x, int y) {
return x+y;
}
public int subtract(int x, int y) {
return x-y;
}
}
Compile the classes, and in command prompt:
java org.apache.axis.wsdl.Java2WSDL -o calculator.wsdl -n urn:com.jijo.Calculator -l http://localhost:8080/axis/services/calcservice com.jijo.Calculator
[This is for creating the WSDL(Java to WSDL)].
After this a wsdl file is created in you folder.
Then Create the Stubs based on this WSDL(WSDL to Java)
java org.apache.axis.wsdl.WSDL2Java -o ..\src -p com.jijo.stubs -s calculator.wsdl
Then the stubs is created .
Replace the
CalcserviceSoapBindingImpl.java to the following
/** * CalcserviceSoapBindingImpl.java * * This file was auto-generated from WSDL * by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter. */
package com.jijo.stubs;
import com.jijo.CalculatorImpl;
public class CalcserviceSoapBindingImpl implements com.jijo.stubs.Calculator{ com.jijo.Calculator calculator = new CalculatorImpl(); public int add(int in0, int in1) throws java.rmi.RemoteException { return calculator.add(in0, in1); }
public int subtract(int in0, int in1) throws java.rmi.RemoteException { return calculator.subtract(in0, in1); }
}
create a jar eg: cal.jar based on the classes and put into axis.war/WEB-INF/lib folder
start the tomcat/jboss server.Then
Deploy into axis.war using ,
java org.apache.axis.client.AdminClient ..\src\com\jijo\stubs\deploy.wsdd
One server-config.wsdd file is created in the axis.war folder.
Then restart the server.
Check the wsdl file getting using,in browser
http://localhost:8080/axis/services/calcservice?wsdl
Create a client class
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.jijo.stubs.CalculatorService;
import com.jijo.stubs.CalculatorServiceLocator;
public class CalcClient {
public static void main(String[] args) {
CalculatorService service = new CalculatorServiceLocator();
try {
int result = service.getcalcservice().add(10, 20);
System.out.println("Result :"+result);
result = service.getcalcservice().subtract(10, 20);
System.out.println("Result:"+result);
} catch (RemoteException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
}
}
}
Wednesday, May 27, 2009
JBoss -- Memory configuration
jboss/bin/run.conf file,
if [ "x$JAVA_OPTS" = "x" ]; then
JAVA_OPTS="-Xms512m -Xmx1024m -XX:PermSize=512m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000"
fi
Friday, May 22, 2009
String array to java.util.List
String array[] = {"jijo","mathew"};
List
Thursday, May 21, 2009
Convert String to Blob and Blob to String
String data = "hello world";
java.sql.Blob blob = org.hibernate.Hibernate.createBlob(data.getBytes());
Convert Blob to String
byte[] bdata = blob.getBytes(1, (int)blob.length());
String data1 = new String(bdata);
