Tuesday 18 November 2008

[ExtJs] Ext.grid.GroupingView : groupTextTpl

Get data for GroupingView

grid = new Ext.grid.GridPanel({
id: getGridArea,
ds: createStore,
cm: this.columnModelFile(),
view: new Ext.grid.GroupingView({
forceFit:true,
groupTextTpl: '{text}|{[ values.rs[0].data["state"] ]} ({[values.rs.length]} {[values.rs.length > 1 ? "Devices" : "Device"]})'
}),
// viewConfig: {
// forceFit:true
// },
sm: selectionModel,
width: 500,
height: 250,
//title: 'Firmware File List',
collapsible: false,
animCollapse: true,
bbar: pagingTool
});

Monday 10 November 2008

[Restlet with Spring DM]

How you can create restlet with Spring DM

1. need update 6 files
- web.xml
- applicationContext-osgi.xml
- applicationContext.xml
- MANIFEST.MF
- TestApplication.java
- TestDefaultResource.java

2. main point

use "org.restlet.component" as context-param

in web.xml add below line


3.
[context-param]
[param-name]org.restlet.component[/param-name]
[param-value]component[/param-value]
[/context-param]

4. "component is from "applicationContext.xml" file

[bean id="component" class="org.restlet.ext.spring.SpringComponent" ]
[property name="defaultTarget" ref="application" /]
[/bean]

5. "application" is from same file "applicationContext.xml" file

[bean id="application" class="applicationPackage.TestApplication"][/bean]

6. TestApplication.java
import TestDefaultResouce;
import org.restlet.Application;
import org.restlet.Context;
import org.restlet.Restlet;
import org.restlet.Router;

public class EamApplication extends Application {

public EamApplication() {
super();
// TODO Auto-generated constructor stub
}

public EamApplication(Context context) {
super(context);
}

@Override
public Restlet createRoot() {
Router router = new Router(getContext());
router.attachDefault(TestDefaultResouce.class);
return router;
}
}

7. TestDefaultResouce.java

import org.restlet.Context;
import org.restlet.data.MediaType;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.resource.Representation;
import org.restlet.resource.Resource;
import org.restlet.resource.StringRepresentation;
import org.restlet.resource.Variant;

public class EamDefaultResouce extends Resource {

public EamDefaultResouce() {
super();
// TODO Auto-generated constructor stub
}

public EamDefaultResouce(Context context, Request request, Response response) {
super(context, request, response);
getVariants().add(new Variant(MediaType.TEXT_PLAIN));
}

@Override
public Representation getRepresentation(Variant variant){
Representation representation = new StringRepresentation("index page", MediaType.TEXT_PLAIN);
return representation;
}
}

Thursday 6 November 2008

[Error - Rest] com.noelios.restlet.Engine createHelper

====== Error message (Rest) ======
com.noelios.restlet.Engine createHelper
No available server connector supports the required protocols


==== Solution ======
need "com.noelios.restlet.ext.jetty_6.1.jar" file

org.mortbay.jetty.ajp.jar
org.mortbay.jetty.https.jar
org.mortbay.jetty.jar
org.mortbay.jetty.util.jar

=== You might see other error message ====
Exception in thread "main" java.lang.NoClassDefFoundError: org/mortbay/jetty/Connector

=== Solution ===
need "org.mortbay.jetty.jar" file

=== You might see other error message ====
Exception in thread "main" java.lang.NoClassDefFoundError: org/mortbay/component/LifeCycle

=== Solution ===
need "org.mortbay.jetty.util.jar" file

=== You might see other error message ====
Exception in thread "main" java.lang.NoClassDefFoundError: org/mortbay/jetty/ajp/Ajp13SocketConnector

=== Solution ===
need "org.mortbay.jetty.ajp.jar" file

=== You might see other error message ====
Exception in thread "main" java.lang.NoClassDefFoundError: org/mortbay/jetty/security/SslSelectChannelConnector

=== Solution ===
need "org.mortbay.jetty.https.jar" file

Monday 3 November 2008

[Error] NoClassDefFoundError org/apache/commons/codec/DecoderException

==== Error Message ====
NoClassDefFoundError org/apache/commons/codec/DecoderException



==== Solution =====
You need org.apache.commons.codec.jar file

[Error] java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

=== Error MEssage ===
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

== Solution ===
you need "commons-logging.jar" file

Sunday 2 November 2008

[Erro] Axis2 - Eclipse

=== Error message =====
The Axis2 facets cannot be installed since the Axis2 runtime location has not been set. Please go to the Web Services preference page and set the Axis2 runtime


==== Solution ====
Eclipse
Window > Preferences > Web Services > Axis2 Preferences > Axis2 Runtime
Setup Axis2 location and check "Axis2 runtime loaded successfully!!!"

Tuesday 28 October 2008

[ExtJs] Grid Panel - layout:'fit' problem

layout:'fit' is not working collectly in IE 6.

You should put style

please add

.x-grid3-header-offset {width: auto;}

[ExtJs] dynamically Add button PagingToolBar

==== create PagingToolbar ====
var toolBar = new Ext.PagingToolbar({
pageSize:10,
store:store,
displayInfo:true,
displayMsg: 'total{2} {0} - {1}',
emptyMsg:'no data'
})

======== create Toolbar Button =======
var sbun = new Ext.Toolbar.Button({
pressed: true,
enableToggle: false,
text: 'Create',
id: 'createId',
cls: ''
})


======= create Grid with PagingToolbar =======
var grid = new Ext.grid.GridPanel({
el:'Firmware-grid',
store:store,
cm:cm,
//sm: new Ext.grid.RowSelectionModel({selectRow:Ext.emptyFn}),
viewConfig:{
forceFit:true
},
title:' grid title',
width:500,
height:500,
loadMask:true,
frame:false,
bbar:toolBar
});

====== Add Toolbar Button ====
grid.render();
grid.getBottomToolbar().add('-',sbun);

Monday 27 October 2008

[ExtJs] - Update Panel Data

== updating panel ==
panel1 = new Ext.Panel({
html: 'panel one'
});
panel2 = new Ext.Panel({
html: 'panel two'
});

== default panel ==
fitpanel = new Ext.Panel({
layout:'fit',
region: 'center'
});

=== change option ==
fitpanel.remove(panel1, true);
panel2 = new Ext.Panel({
html: 'panel two'
});
fitpanel.add(panel2);
fitpanel.doLayout();

[ExtJs] - Auto Width in Panel of Grid

" layout:'fit' "



upPanel = new Ext.Panel({
title:'Device List',
region:'center',
collapsible:false,
reload:true,
width:400,
height:200,
minSize: 100,
autoScroll:true,
bodyStyle:'background-color: white',
items: [this.gridEam()],
layout:'fit'
});

[ExtJS] - Icon in the top of Panel

tools: [{id: 'refresh', handler: refreshO, scope: refreshO}]

var refreshO = function() {
do something.
}

Friday 24 October 2008

[ExtJs] Grid button in PagingToolbar

===== js file =======

bbar: new Ext.PagingToolbar({
pageSize: 25,
store: store,
displayInfo: true,
displayMsg: 'Displaying topics {0} - {1} of {2}',
emptyMsg: "No topics to display",
items:[
'-', {
pressed: true,
enableToggle:true,
text: 'Show Preview',
iconCls: 'x-btn-text-icon',
//cls: 'x-tbar-loading',
toggleHandler: toggleDetails
},'-', {
pressed: true,
enableToggle:true,
text: 'Show Preview',
iconCls: 'x-btn-text-icon',
//cls: 'x-tbar-loading',
toggleHandler: toggleDetails
}]
})

=========== css part ==============
.x-tbar-loading{
background-image:url(../../resources/images/default/grid/refresh2.gif)!important;
}
.x-btn-text-icon{
background-image:url(../../resources/images/default/grid/group-by.gif)!important;
}

Wednesday 22 October 2008

[ExtJs] Namespace example

=== html file ====
[!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"]
[html lang="en"]
[head]
[meta http-equiv="content-type" content="text/html; charset=iso-8859-1"]
[title]namespace test page[/title]
[!-- Bring in the ExtJs Libraries and CSS --]
[link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" /]
[script type="text/javascript" src="../../adapter/ext/ext-base.js"] [/script]
[script type="text/javascript" src="../../ext-all-debug.js"] [/script]
[!-- Place the page specific js here --]
[script type="text/javascript" src="applayout.js"] [/script]
[!-- End page specific js --]

[script type="text/javascript"]
Ext.onReady(myNameSpace.app.init, myNameSpace.app);
[/script]

[/head]
[body]


[/body]
[/html]


===== js file ====
Ext.BLANK_IMAGE_URL='../resources/images/default/s.gif';

Ext.namespace('myNameSpace');

Ext.namespace('myNameSpace2');

myNameSpace.app = function() {
return {
init:function(){
alert('application successfully initialized');
//this.testInit();
var aa = myNameSpace2.app.testIni('test value1');
alert(aa);
this.testInit(aa+" : 2");
},
testInit: function(getValue){
alert(getValue);
}
}
}();


myNameSpace2.app = function(){
return{
testIni:function(getValue) {
var ss = getValue;
return ss;
}
}
}();

Wednesday 15 October 2008

[ExtJs] Popup - clean Window object

var button = Ext.get('show-btn');

button.on('click', function(){


var win = new Ext.Window({
title: 'Layout Window',
closable:true,
width:600,
height:350,
//border:false,
plain:true,
buttons: [{
text: 'Save',
handler: function(){
if(nav.getForm().isValid()){
nav.getForm().submit({
url: 'uploadFile.htm',
method:'POST',
waitMsg: 'Uploading your file...',
success: function(nav, o){
popupMsg('Success', 'Processed file "'+o.result.file+'" on the server');
dlgPopup.hide();
},
failure: function() {
popupMsg('Fail', 'Fail to upload file "'+o.result.file+'" on the server');
dlgPopup.hide();
}

});
}
}
},{
text:'Close',
handler:function(){
win.close();
}
}]
});

win.show(this);
});

Tuesday 14 October 2008

[ExtJs] TimeField example

var startTimePicker = new Ext.form.TimeField({
triggerClass: 'x-form-time-trigger',
fieldLabel: 'Start time',
name: 'starttime',
editable:false,
value:'',
format:"H:i:s",
value: new Date()
});
var endTimePicker = new Ext.form.TimeField({
triggerClass: 'x-form-time-trigger',
fieldLabel: 'End time',
name: 'endtime',
editable:false,
format:"H:i:s",
value: new Date()
});
startTimePicker.setValue('');
endTimePicker.setValue('');

Monday 13 October 2008

[JSTL] - if / else if (when)

[c:choose]
[c:when test="${commnad == 'scheudleList'}"]
[json:object]
[json:property name="total" value="${totalCount}"/]
[json:array name="data" var="task" items="${utilSchdule}"]
[json:object]
[json:property name="id" value="${task.id}"/]
[json:property name="taskName" value="${task.taskName}"/]
[json:property name="applicationSymbolicName" value="${task.applicationSymbolicName}"/]
[json:property name="endTime"]
[fmt:formatDate value="${task.endTime}" pattern="dd.MM.yyyy HH:mm"/]
[/json:property]
[json:property name="nextTime"]
[fmt:formatDate value="${task.nextTime}" pattern="dd.MM.yyyy HH:mm"/]
[/json:property]
[json:property name="userId" value="${task.userId}"/]
[json:array name="selectedIds" var="selectedId" items="${selectedIds}"]
[c:out value="${selectedId}"/]
[/json:array]
[/json:object]
[/json:array]
[/json:object]
[/c:when]
[/c:choose]

Friday 10 October 2008

[ExtJs] - Ajax example

====== with Connection ===========

var conn = new Ext.data.Connection();
conn.request({
url: 'history.jsp',
method: 'POST',
params: {"metaID": metaID, columnName: field},
success: function(responseObject) {
showHistoryDialog(responseObject.responseText);
},
failure: function() {
}
});

====== with getForm().submit===========
nav.getForm().submit({
url: 'am-TaskManagement-Tasks-Value.htm',
params: {command: 'scheudleUpdate'},
method:'POST'
});

Wednesday 8 October 2008

simple File upload

========= HTML =============
[html]
[head]
[meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"]
[title]1[/title]
[body]
[form method="post" action="upload1.jsp" enctype="multipart/form-data"]
Name : [input type="text" name="userName" value="myname"][br]
file : [input type="file" name="upfile"][br]
[input type="submit" value="submit"]
[/form]
[/body]
[/html]

====================

[head]
[meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"]
[title] 1[/title]
[/head]
[body]
[%
String path = "C:/test111/";
DiskFileUpload upload = new DiskFileUpload();
upload.setSizeMax(1024 * 1024);
upload.setSizeThreshold(4096);
upload.setRepositoryPath(path + "temp");
List items = upload.parseRequest(request);


FileItem item1 = (FileItem) items.get(0);
String name = item1.getString("euc-kr");
out.println("Name : "+name + "[br]");


FileItem item2 = (FileItem) items.get(1);
String fileName = item2.getName();
fileName = fileName.substring(fileName.lastIndexOf("\\") + 1);
long fileSize = item2.getSize();
File file = new File(path + "/" + fileName);
item2.write(file);
out.println(fileName + " !!!");
%]
[/body]
[/html]

[Spring] file upload example

you need two jar file library.

- commons-io-1.4.jar
- commons-fileupload-1.2.jar

=== HTML ====
[form method="post" action="uploadFile.htm" enctype="multipart/form-data"]
[input type="file" name="file1"/]
[input type="submit"/]
[/form]

============ dispatcher-servlet.xml ====================

[bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"]
[property name="maxUploadSize" value="100000"/]
[property name="uploadTempDir" ref="uploadDirResource"/]
[/bean]

[bean id="uploadDirResource"
class="org.springframework.core.io.FileSystemResource"]
[constructor-arg]
[value]C:/test111[/value]
[/constructor-arg]
[/bean]


==================== Controller =====
@Override
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)throws ServletException, IOException {


MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest)request;

MultipartFile filea = multipartRequest.getFile("file1");


InputStream inputStream = null;
OutputStream outputStream = null;
if (filea.getSize() > 0) {


inputStream = filea.getInputStream();
File realUpload = new File("C:/");
outputStream = new FileOutputStream("C:/test111/"+filea.getOriginalFilename());
System.out.println("====22=========");
System.out.println(filea.getOriginalFilename());
System.out.println("=============");
int readBytes = 0;
byte[] buffer = new byte[8192];
while ((readBytes = inputStream.read(buffer, 0 , 8192))!=-1){
System.out.println("===ddd=======");
outputStream.write(buffer, 0, readBytes);
}
outputStream.close();
inputStream.close();
}

return new ModelAndView("fileupload");
}

Tuesday 7 October 2008

Get All parameter (key and value)

Enumeration ss = request.getParameterNames();

while(ss.hasMoreElements()) {

String key = (String)ss.nextElement();
String value = request.getParameter(key);
System.out.println(key + " : " + value+"
");
}

// if value is array type such as check box
/*
String test[] = request.getParameterValues("test");

if(test != null) {
for(int i=0; i < test.length; i++) {
System.out.println("test[" + i + "] : " + test[i] );
}
}
*/

[ExtJs] reload store from panel

var store = new Ext.data.Store({
.....
.....
.....

var grid = new Ext.grid.GridPanel({
id:'gridpanel'
ds:store,
.....
.....
.....


Ext.getCmp('gridpanel').getStore().reload();

[ExtJs] Simple Panel example

var buttonHTML = 'put html source here';

var ct = new Ext.Panel({
renderTo:'pagingJson-grid',
frame:true,
title:'Book List',
width:500,
height:400,
layout:'border',
items: [
grid,
{
id: 'detailPanel',
region: 'center',
bodyStyle: {
//background: '#ffffff',
padding: '7px'
},
html: buttonHTML
}
]
})

[ExtJs] get data from grid

=== 1 ===================
grid.getSelectionModel().on('rowselect', function(sm, rowIdx,r){

alert(r.data.my_id+" : "+r.data.organization);
alert(rowIdx);
alert(grid.getSelectionModel().getCount());
alert(grid.getSelectionModel().getSelected().get('my_id'));

//bookTpl.overwrite(detailPanel.body, r.data);
});
=== 2 =================================

var getData = grid.getSelectionModel().getSelected();
alert(getData.get('my_id'));

=== 3: multi selection =================================

var getData = grid.getSelections();
for (var i = 0 ; i < getData.length ;i++) {
alert(getData[i].get('my_id'));
}

[ExtJs] Call object function from the different js file

=========== bb.js Other js file =========
var uploadPopup = function(){

var win,dlgPopup, nav;

return {
init:function(){
alert('start init');
},{
doSomething:function(){
alert('start do somthing');
}

}
}();

======== aa.js : Call this method object from original js file ========
Ext.get('button2').on('click', function(){
uploadPopup.init();
})

[ExtJs] popup - file upload UI

[ExtJs] popup - file upload UI

Tip: "autoHeight: true"

see here

* Ext.FormPanel
* Ext.Window

Monday 6 October 2008

[ExtJs] - popup example

ExtJs Popup Example (modal popup)

This is using "Ext.Window" and "Ext.FormPanel"

see here

Sunday 5 October 2008

Create OSGI bundle from library jar file

* Create OSGI bundle from library jar file
http://blog.springsource.com/2008/02/18/creating-osgi-bundles/

you need bnd.jar file

this is working with command line

- java -jar bnd.jar wrapprint "library name(such as json-lib-2.2.2-jdk1.5.jar)"

ex) java -jar bnd.jar print json-lib-2.2.2-jdk1.5.jar

ex) java -jar bnd.jar wrap json-lib-2.2.2-jdk1.5.jar

Json : working with JSP , extJs

simple sample with jsp, extjs :
This is paging grid example from extjs for ui

5 files

* PagingBean.java
* CreateJson.java
* twopaging.js
* twoPaging.html
* sendTwoPaging2.jsp

download sample files

Simple List to Json example

Download 6 package jar files

commons-lang 2.3
commons-beanutils 1.7.0
commons-collections 3.2
commons-logging 1.1
ezmorph 1.0.4.jar
json-lib-2.2.2-jdk15.jar

Download all

=== Test source from List to Json ====
============== JsonTest =======================
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;


public class JsonTest {

public void Bean2Json(){
MyBean myBean1 = new MyBean();
myBean1.setId(1);
myBean1.setName("a");

MyBean myBean2 = new MyBean();
myBean2.setId(2);
myBean2.setName("b");

List mybeanList = new ArrayList();
mybeanList.add(myBean1);
mybeanList.add(myBean2);

JSONArray jsonArray = JSONArray.fromObject(mybeanList);
System.out.println("==== : "+jsonArray);

Map map = new HashMap();
map.put("beanlist", jsonArray);

JSONObject jsonObject = JSONObject.fromObject(map);
System.out.println("==== json :"+jsonObject);
}
}

======= MyBean.java =======

public class MyBean {

private int Id;
private String Name;

public int getId() {
return Id;
}
public void setId(int id) {
Id = id;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}


}


===== runtTest.java =========


public class runTest {

/**
* @param args
*/
public static void main(String[] args) {
JsonTest jsonTest = new JsonTest();
jsonTest.Bean2Json();

}

}

Thursday 28 August 2008

Error : interface org.hibernate.jdbc.ConnectionWrapper is not visible from class loader

Error Message : interface org.hibernate.jdbc.ConnectionWrapper is not visible from class loader

Full Error Message

Caused by: java.lang.IllegalArgumentException: interface org.hibernate.jdbc.ConnectionWrapper is not visible from class loader
at java.lang.reflect.Proxy.getProxyClass(Unknown Source)
at java.lang.reflect.Proxy.newProxyInstance(Unknown Source)
at org.hibernate.jdbc.BorrowedConnectionProxy.generateProxy(BorrowedConnectionProxy.java:67)
at org.hibernate.jdbc.ConnectionManager.borrowConnection(ConnectionManager.java:163)
at org.hibernate.jdbc.JDBCContext.borrowConnection(JDBCContext.java:111)
at org.hibernate.impl.SessionImpl.connection(SessionImpl.java:359)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:510)
... 31 more


In this case, your manifest file is not correctly.
Please check it, you might miss "org.hibernate.jdbc;version="3.2.6.ga" bundle
or check with below example mainifest file bundle list

org.aopalliance.aop;version="1.0.0",
org.apache.commons.dbcp;version="1.2.2.osgi",
org.apache.log4j;version="1.2.15",
org.hibernate;version="3.2.6.ga",
org.hibernate.classic;version="3.2.6.ga",
org.hibernate.criterion;version="3.2.6.ga",
org.hibernate.hql.ast;version="3.2.6.ga",
org.hibernate.jdbc;version="3.2.6.ga",
org.hibernate.proxy;version="3.2.6.ga",
org.hibernate.usertype;version="3.2.6.ga",
org.springframework.aop;version="2.5.4",
org.springframework.aop.framework;version="2.5.4",
org.springframework.beans;version="2.5.4",
org.springframework.beans.factory.config;version="2.5.4",
org.springframework.core;version="2.5.4",
org.springframework.jmx.export;version="2.5.4",
org.springframework.orm.hibernate3;version="2.5.4",
org.springframework.orm.hibernate3.support;version="2.5.4",
org.springframework.transaction;version="2.5.4",
org.springframework.transaction.annotation;version="2.5.4",
org.springframework.transaction.interceptor;version="2.5.4",
org.springframework.transaction.support;version="2.5.4"

Tuesday 5 August 2008

Ms-sql : auto generate primary key value

Open table design

Check properties on the right side

Table Designer > Identity column : please select primary key column name

Then ms sql will generate primary key value automatically.

org.hibernate.HibernateException: No Hibernate Session bound to thread

error message : org.hibernate.HibernateException: No Hibernate Session bound to thread

You did not insert "annotation" in the source.
such as

"@Transactional"
"@SuppressWarnings("unchecked")"
"@Transactional(readOnly = true)"

Wednesday 30 July 2008

Eclipse- Show suggestion word , line number

Eclipse setup
*==== show line number ====*
Window > Preferences > General > Editors > Text Editors > "Show line numbers"


*==== show suggestion word =====*
Window > Preferences > Java > Editor > Context Assist > Advanced >
check all check box "Select the proposal kinds contained in the 'default' content assist list

Tuesday 29 July 2008

eclipse- Proxy Server Setting 2

Window > Property > Internet > Proxy

IP : 10.88.193.132
Port :3128

Tuesday 22 July 2008

Spring osgi - good tutorial

http://springosgi.googlepages.com/

If you have the problem while you are following the example from the site, please
use different pom.xml file.


When you progress the sample from the tutorial site, please use another pom.xml file.

updated pom.xml file

Wednesday 16 July 2008

Install SpringIDE or Maven in Eclipse 3.4 ( GANYMEDE )

1. Help
2. Software update
3. Add Site
4. Enter http://springide.org/updatesite
4-1. For Maven - http://m2eclipse.sonatype.org/update/
5. Click checkbox next to http://springide.org/updatesite to expand.
5-1 For Mave - http://m2eclipse.sonatype.org/update/ to expand
6. Check all sub option under SpringIDE (Maven)
7. Install
8. You will have below error message
======================================================
The software items you selected may not be valid with your current installation....
===================================================
9. Click Yes
10. Uncheck
"Spring IDE Dependencies (only for Eclipse 3.2.x)"
"Spring IDE Mylyn Integration (optional)"
10-1 "Subclipse Integration for Maven (Optional)"
11. Click Next

Tuesday 15 July 2008

JSON : Array List <> JSON 2

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;


public class testMain {

/**
* @param args
*/
public static void main(String[] args) {

MyBean myBean = new MyBean();
myBean.setId(1);
myBean.setName("one");
MyBean myBean2 = new MyBean();
myBean2.setId(2);
myBean2.setName("two");

List mybeanList = new ArrayList();
mybeanList.add(myBean);
mybeanList.add(myBean2);

JSONArray jsonArray = JSONArray.fromObject(mybeanList);
System.out.println("mybean list -----"+jsonArray);

Map map0 = new HashMap();
map0.put("success", true);

JSONObject mapObject = JSONObject.fromObject(map0);
System.out.println("map0 - "+mapObject);

Map map = new HashMap();
map.put("data", jsonArray);

JSONObject jsonObject = JSONObject.fromObject(map);
System.out.println("json - "+jsonObject);

}

}

Thursday 10 July 2008

php + mysql : development enviroment setup

* Setup PHP enviroment under window OS System

http://blog.naver.com/jjeowl?Redirect=Log&logNo=40025454157


After you setup
please test with under example php file
=== connectTest.php ====


$dbhost = "localhost";
$dbname = "test";
$dbuser = "root";
$dbpass = "1111";

$conn = @mysql_connect($dbhost,$dbuser,$dbpass);
if($conn)
{
if(!@mysql_select_db($dbname,$conn))
{
echo "DB Select Error!";
exit();
}else{

echo "Success connection !";

}
}
else
{
echo "DB Connection Error!";
exit();
}

?>

Monday 7 July 2008

JSON : Array List <> JSON

Converting method between array List and JSON

You need some jar files.
1. json-lib-2.2.2-jdk15.jar
2. commons-beanutils.jar
3. commons-lang.jar
4. commons-collections.jar
5. commons-logging.jar
6. ezmorph-1.0.4.jar

Please set classpath those jar files.
And here is sample source to change from ArrayList to JSON.


import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;

public class testA {

/**
* @param args
*/
public static void main(String[] args) {

List mybeanList = new ArrayList();
mybeanList.add("S");
mybeanList.add("b");

JSONArray jsonA = JSONArray.fromObject(mybeanList);
System.out.println(jsonA);
}

}

Friday 4 July 2008

error : hibernate with Data type in DB

* Error Message
"java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Date"

You might have data type column in DB table and read it with hibernate.
In this case , you should update "dataSource.xml" file
Add " p:zeroDateTimeBehavior="convertToNull" "

=== Pull xml file =====
[?xml version="1.0" encoding="UTF-8"?]

[beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"]

[bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
p:driverClassName="com.mysql.jdbc.Driver"
p:url="jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=euckr&zeroDateTimeBehavior=convertToNull"
p:username="root" p:password="1111"]

[/beans]

Tuesday 1 July 2008

Aptana plugin

Plugging Aptana into an existing Eclipse configuration

http://update.aptana.com/install/studio/3.2/

Detail information
http://www.aptana.com/docs/index.php/Plugging_Aptana_into_an_existing_Eclipse_configuration

Thursday 26 June 2008

Spring , Hibernate Sample

This is Spring 2.0 + Hibernate3 sample source.

It is working with mysql + Eclipse

Simple BBS sample source.

add > view list > delete , update

sql file is in sql folder to create table

download sample source

Monday 23 June 2008

Eclipse - Save UTF-8 character

Error message from Eclipse when you try to save the file
========================================================================
save could not be completed.
Reason:
some characters cannot be mapped using "ISO-8859-1" character encoding.
Either change the encoding or remove the characters which are not supported
by the "ISO-8859-1" character encoding.
==========================================================================

Please go to "Windows > Preferences > General > Content Types > Text > JSP or ...

JSP > Default encoding > UTF-8 and click update button

Monday 9 June 2008

Maven error -Proxy setting

Error message from Maven
=======
Build Error

The plugin 'org.apache.maven.plugins:maven-archetype-plugin' does not exist or no
valid version could be found
=======

You should check the proxy server setting.
so Please check it from web browser
From Browser
Tools > Internet option > Connections > setting Lan > copy proxy setting file address
(maybe "http://:8088/samxxxxcs.pac")
paste "http://:8088/samxxxxcs.pac" address into web browser URL

and download pac script file
open it

the end of that script file you will see
Return "PROXY 168.XXX.XX.XXX:8080"
Copy address and port number

open settings.xml from maven install folder > conf > settings.xml
change
==============================

[localRepository]C:\java\maven\.m2\repository[/localRepository]

==================================
[proxy]
[id]optional[/id]
[active]true[/active]
[protocol]http[/protocol]
[host]168.219.61.250[/host]
[port]8080[/port]
[nonProxyHosts]local.net,some.host.com[/nonProxyHosts]
[/proxy]

setting.xml

Wednesday 4 June 2008

Error to generate Web Service from eclipse , Axis2

When you have some problem for generating Web Service from Eclipse with Axis2,
you should check set up of eclipse for Axis2.

From Eclipse
Window > Preference > Web Services > Axix2 Preferences > Axis2 Runtime
setup "Axis2 Runtime Location" from "Browse" button : setup Axis2 folder
then you will see the message on the bottom "Axis2 runtime loaded successfully!!!"

Click ok and process generating Web service again.

Monday 2 June 2008

Web Services Reference List Site

http://openframework.or.kr/JSPWiki/Wiki.jsp?page=WebServices

Tuesday 27 May 2008

build .xml file for compiling with the different version

* this example show how we can build from the different jdk version.

click here

Wednesday 21 May 2008

Ant resource register sample

Check build.xml for registering resource with jar file.

Click here

[Error] Cannot load SchemaTypeSystem. Unable to load class with name schemaorg_...

Error Message :

ClassNotFoundException : Cannot load SchemaTypeSystem. Unable to load class with name schemaorg_apache_xmlbeans.system.s68C41DB812F52C975439BA10FE4FEE54.TypeSystemHolder. Make sure the generated binary files are on the classpath.

"s68C41DB812F52C975439BA10FE4FEE54" this part will be different

When you have this kind of error
The TypeSystemHolder.class generated by WSDL2Java is not be placed in your classpath in order to avoid this error.

Please copy TypeSystemHolder.class from "resource/schemaorg_apache_xmlbeans/system/s68C41DB812F52C975439BA10FE4FEE54" folder.

And Paste TypeSystemHolder.class file into your classpath folder (build/classes/schemaorg_apache_xmlbeans/system/s68C41DB812F52C975439BA10FE4FEE54) folder

Wednesday 14 May 2008

Eclipse- Register Resource

Window > Preferences > Java > Classpath Variable

New ---
Name : AXIS2_REPO
Path : D:/Language/java/Axis2/axis2-1.3/repository

OK

==========================================================

* Class Path for whole folder

Build Path > Source Tab > Add Folder > Select some folder > OK

Selected folder is going to set as Classpath (under lib>classes folder)

Eclipse - WS Client [Web App Libraries] - Axis2

You should insert Axis2 library into "Referenced Libraries" for compile the source
and "Web App Libraries" (Project path\WebContent\WEB-INF\lib)

- You can change the path "Referenced Libraries" from Eclipse.
- Web App Libraries :
1. Copy all jar file from "AXIS2_HOME\lib"
*** Please do not copy "jsp-api.jar" file

- And Refersh Eclise Project

Eclipse - Create User's "Add Library"

- Create User's Library

* Window > Preference > Java > Build Path > User Libraries

* New > Type "Axis2" > "Add JARs" > Import Axis\lib\all jar files

After create "user libraries"

* Build Path > Configure Build Path > Add Library > User Library > select Axis2 Library which was created previous step.

Sunday 20 April 2008

ANT build.xml sample

Please use ant sample , just change some value

Click Here

Wednesday 16 April 2008

[Spring] Simple MVC Web application Example 2

[Spring] Simple MVC Web application Example 2

- Display Current Time with parameter under MVC model
(* Developing and Configuring the Views and the Controller)

From http://www.springframework.org/docs/Spring-MVC-step-by-step/index.html

Click Here

[Spring] Basic Example 1

[Spring] Simple MVC Web application Example

Modify from Spring reference
http://www.springframework.org/docs/Spring-MVC-step-by-step/index.html

- Create Control and just display hello world
click here

Monday 14 April 2008

Spring Eclipse IDE sample

- install Eclipse IDE for spring and simple demo

* http://www.javabeat.net/articles/2007/09/introduction-to-spring-ide-2-0/


- Sample source
click Here

Thursday 10 April 2008

JBoss Error : Port already in use: 1098

when you run jboss from "run.bat" file, you might have the error "Port already in use: 1098"

In this case, please open /server/default/conf/jboss-service.xml
and change from "from 1098 to 1122(a port hasn't been taken)".

Then restarted the JBOSS, everything looks ok now.

Monday 7 April 2008

Exception Example

class NewExceptionTest {
public static void main(String args[]) {
try {
startInstall();
copyFiles();
} catch (SpaceException e) {
System.out.println("error : " + e.getMessage());
e.printStackTrace();
System.out.println("not enough space.");
} catch (MemoryException me) {
System.out.println("error : " + me.getMessage());
me.printStackTrace();
System.gc(); //expand memory from Garbage Collection
System.out.println("install again.");
} finally {
deleteTempFiles(); // delete temp files
} // end of try
} // end of main

static void startInstall() throws SpaceException, MemoryException {
if(!enoughSpace()) // if not enought space...
throw new SpaceException("not enought space.");
if (!enoughMemory()) // if not memory space..
throw new MemoryException("not enought memory space.");
} // end of startInstall

static void copyFiles() { /* copy code. */ }
static void deleteTempFiles() { /* delete temp files code .*/}

static boolean enoughSpace() {
// code for checking enough space.
return false;
}
static boolean enoughMemory() {
// code for checking memory space.
return true;
}
} // end of ExceptionTest

class SpaceException extends Exception {
SpaceException(String msg) {
super(msg);
}
}

class MemoryException extends Exception {
MemoryException(String msg) {
super(msg);
}
}

Thursday 27 March 2008

Java Interface concept - JDBC way

==== Developer A side ======
class InterfaceTest2 {
public static void main(String[] args) {
A a = new A();
a.methodA();
}
}


==== Developer B side ======
=== Do not change Class name "A" and method "methodA"
=== Except two factors B side can change anything

class A {
void methodA() {
I i = InstanceManager.getInstance();
i.methodB();
}
}

interface I {
public abstract void methodB();
}

class B implements I {
public void methodB() {
System.out.println("methodB in B class");
}
}

class InstanceManager {
public static I getInstance() {
return new B();
}
}

Friday 21 March 2008

Java Split Example

public class Test {
public static void main(String[] args) {
String temp = "123.456";

String[] temp2 = new String[2];

temp2 = temp.split("[.]");

System.out.println(temp2[0]);
}
}

Thursday 20 March 2008

Simple JSon Example

<html>
<head>
<title>JSON test</title>

</head>
<body>

<select id="sel">
</select>

<script type="text/javascript">
var cafe = {"cafelist" : [
{"name" : "aaaaaa", "clubid" : "11111111"},
{"name" : "bbbbbbb", "clubid" : "2222222"},
{"name" : "CCC", "clubid" : 123213213}
]
};

for (var i=0; i<cafe.cafelist.length; i++)
{
//alert(cafe.cafelist[i].name + "," + cafe.cafelist[i].clubid);
var s = document.getElementById("sel");
s.options.add(new Option(cafe.cafelist[i].name, cafe.cafelist[i].clubid),i);
}
</script>
</body>
</html>

Tuesday 18 March 2008

Java Interface concept example2

===== TVBoard.java ===========
public interface TVBoard {

public void channelDown();
public void channelUp();
public void volumeDown();
public void volumeUp();
public void powerOnOff(boolean power);
}

========== SSgTV.java ===========

public class SSgTV implements TVBoard {

private String name = "SSg TV";
private int volume = 5;
private int channel = 7;
private boolean power = false;

public SSgTV() {
System.out.println("SSg TV is created.");
}

@Override
public void channelDown() {
this.channel -= 1;
System.out.println(this.name+"- channelDown");
}

@Override
public void channelUp() {
this.channel += 1;
System.out.println(this.name+" + channelIp");
}

@Override
public void volumeDown() {
this.volume -= 1;
System.out.println(this.name+" - volumnDown");
}

@Override
public void volumeUp() {
this.volume += 1;
System.out.println(this.name+" + volumnUp");
}

@Override
public void powerOnOff(boolean power) {
this.power = power;

if (this.power==false)
System.out.println(this.name+" power off");
else
System.out.println(this.name+" power on");
}

public void SleepTimer(int time) {
System.out.println(time+" please wait for power on or off");

this.powerOnOff(false);
}
}

============== LGsTV.java ==============

public class LGsTV implements TVBoard {

private String name = "LGg TV";
private int volume = 5;
private int channel = 7;
private boolean power = false;

public LGsTV() {
System.out.println("LGs TV is created.");
}

@Override
public void channelDown() {
this.channel -= 1;
System.out.println(this.name+"- channelDown");
}

@Override
public void channelUp() {
this.channel += 1;
System.out.println(this.name+" + channelIp");
}

@Override
public void volumeDown() {
this.volume -= 1;
System.out.println(this.name+" - volumnDown");
}

@Override
public void volumeUp() {
this.volume += 1;
System.out.println(this.name+" + volumnUp");
}

@Override
public void powerOnOff(boolean power) {
this.power = power;

if (this.power==false)
System.out.println(this.name+" power off");
else
System.out.println(this.name+" power on");
}

public void SleepTimer(int time) {
System.out.println(time+" please wait for power on or off");

this.powerOnOff(false);
}

}

=============== TVTestMain.java =============

public class TVTestMain {

/**
* @param args
*/
public static void main(String[] args) {
TVBoard tvBoard = new SSgTV();
tvBoard.powerOnOff(true);
tvBoard.channelUp();
tvBoard.channelDown();
tvBoard.volumeUp();
tvBoard.volumeUp();
tvBoard.volumeUp();
tvBoard.volumeUp();
tvBoard.powerOnOff(false);
System.out.println();

TVBoard gTvBoard = new LGsTV();
gTvBoard.powerOnOff(true);
gTvBoard.channelUp();
gTvBoard.channelDown();
gTvBoard.volumeUp();
gTvBoard.volumeUp();
gTvBoard.volumeUp();
gTvBoard.volumeUp();
gTvBoard.powerOnOff(false);
}

}

Thursday 13 March 2008

Java Interface concept example

========= Example 1 =================
**** GuguInter.java ***
interface GuguInter {
public static final int input1 = 2;
public static final int input2 = 3;
public void printGugu2();
pulbic void printGugu3();
}

***** PrintGuguClass.java ******

public class PrintGuguClass implements GuguInter {
PrintGuguClass c = new PrintGuguClass();
c.printGugu2();
c.printGugu3();
}

public void printGugu2() {
System.out.println(GuguInter.input1+ " printed");
}

public void printGugu3() {
System.out.println(GuguInter.input2+ " printed");
}

}

============ Example 2 ====================
****** myInterface.java **********
interface myInterface {
public abstract void method();
}

**** CB.java ***********
class CB implements myInterface {
public void method() {
System.out.println("method in CB");
}
}

***** CC.java **********
class CC implements myInterface {
public void method() {
System.out.println("method in CC");
}
}

***** CA.java ********
class CA {
public void method(myInterface mi) {
my.method()
}
}

***** Cmain.java *****
class Cmain {
public static void main(String[] args) {
CA ca = new CA();
ca.method(new CB());
ca.method(new CC());
}
}

Thursday 21 February 2008

osgi sample with web

your first osgi sample with web

here

Tuesday 19 February 2008

OSGI Reference web site

- Starting Point (Neil Barlett's Getting Started with OSGI)
http://neilbartlett.name/blog/osgi-articles/

- OSGi and Gravity Service Binder Tutorial
http://oscar-osgi.sourceforge.net/tutorial/

- Creating OSGi Bundles of Costin Leau : SpringDM(OSGi)
http://blog.springsource.com/main/2008/02/18/creating-osgi-bundles/

- Advanced : Apache Felix OSGi Tutorial
http://felix.apache.org/site/apache-felix-osgi-tutorial.html

Wednesday 13 February 2008

[Linux-Fedora] setting tip VNC , IP, Browser Folder

= Linux System

Tip 1 : Browser Folder
- Double Any folder > Edit > Preferences >
Behavior > check "Always open in browser windows"
- Same as right button click on any folder > Click "Browse Folder"

Tip 2 : IP Setting
- System > Administration > Network (Setup IP)
- System > Preferences > Network Proxy
- Open Web Browser > Edit > Preference > General > Click "Connection Settings.."
> Select "Manual proxy configuration" and setup "Http Proxy value and Prot"

Tip 3 : VNC
- Install VNC in window system
- Go to linux system > System > Preferences > Remote Desktop >
Check "Allow other users to view your desktop"
and "Allow other users to control your desktop"
Uncheck "Ask you for confirmation"

Tip 4 : Connect from Linux to Window share folder
- Place > Connect to Server >
* Service Type : Windows share
* Server : only IP Address (10.99.99.88)
> Click Connect button

Tuesday 12 February 2008

Update from "eclipse IDE for C/C++" to "eclipse WTP"

* how you can update from "eclipse IDE for C/C++" to "eclipse WTP"

If you are not install eclipse all-in-one version ,
you can update WTP or all-in-one version by using below step.

For example, now i want to update from "eclipse IDE for C/C++" to "eclipse WTP",
then firstly, you should install emf plugin first. Otherwise you will be
error message "WTP Common Core(2.0.1....) requires plug-in "org.eclipse.emf.ecore(2.2.0)", or compatible".

So please go to "Help > software updates > Find and install
>search for new features to install > click "New Remote Site..." button

>> easy way : Unzip eclipse All-in-one version
And create local update site and
line to all-in-one version eclipse folder

NAME :EMF
URL :http://update.eclipse.org/tools/emf/updates

===========If you want to update all at on time=====
== NAME :Update Version
== URL : http://update.eclipse.org/updates/3.3/site.xml
== Then select Eclipse SDK 3.3
====================================================


Click Finish Button

Now you update EMF plugin for updating eclipse WTF

Again
So please go to "Help > software updates > Find and install
>search for new features to install > click "New Remote Site..." button

NAME :WTP
URL :http://download.eclipse.org/webtools/updates

Click Finish button

Then you can work for web project with eclipse.

Wednesday 30 January 2008

[Error] Maven for compile

* when you have the error for compiling from maven such as "The plugin 'org.apache.maven.plugins:maven-resources-plugin' does not exi
st or no valid version could be found"

You might have some problem before. So you should make it clear to compile again

Please delete the folder ".m2/repository/org/apache/maven/plugins/maven-resources-plugin"

and try compile again.

[Error] Maven for build

* When you have the error message from Maven such as "org.apache.maven.plugins:maven-archetype-plugin' does not exist or no valid version could be found at org.apache.maven.plugin.version"
It is from disconnect the internet. It might be from proxy server setting.
So you should update %/Maven%\conf\settings.xml" file.

Please open settings.xml file and find element and update like below

[proxies]

[proxy]
[id]optional[/id]
[active]true[/active]
[protocol]http[/protocol]
[username]kiyoung7.hwang[/username]
[password]1111[/password]
[host]168.219.61.250[/host]
[port]8080[/port]
[nonProxyHosts]local.net,some.host.com[/nonProxyHosts]
[/proxy]
[/proxies]

Tuesday 29 January 2008

Eclipse proxy server setting

* If you have the problem to update plugin or software automatically from
"Help > Software Updates > Find and Install "

It might be from proxy server problem.
You should update prox server setting from
"Window > Preferences > General > Network Connection"
Select "Manual proxy configuration: "
and set HTTP proxy 168.219.61.250:8080" (example) and click ok

Thursday 10 January 2008

Link for Jboss

* setup
http://cafe.naver.com/jbossug.cafe
http://cafe.naver.com/doprogrammer.cafe?iframe_url=/ArticleRead.nhn%3Farticleid=1483

* with eclipse
- Tour around Europa : Eclipse for Java EE (Part I)
http://www.thescreencast.com/2007/07/tour-around-europe-eclipse-for-java-ee.html

- Tour around Europa : Eclipse for Java EE (Part II)
http://www.thescreencast.com/2007/07/tour-around-europe-eclipse-for-java-ee_04.html

- How To : JSF in Eclipse Europa (Part I)
http://www.thescreencast.com/2007/07/how-to-jsf-in-eclipse-europa-part-i.html

- How To : JSF in Eclipse Europa (Part II)
http://www.thescreencast.com/2007/07/how-to-jsf-in-eclipse-europa-part-ii.html

Wednesday 9 January 2008

error "Waiting For Virtual Machine To Exit" in eclipse

* error "Waiting For Virtual Machine To Exit" in eclipse

When you have "Waiting For Virtual Machine To Exit" message and did not change any
progress , you might install "Axis2 Code Generator" in Eclipse.

In order to solve this problem, you should change ANT home setting in eclipse.
Because when you install "Axis2 Code Generator" in eclipse , it change the
ANT HOME setting.

So please go to "Window > Preference > Ant > Runtime". There will be "Ant Home Entires" part. You can confirm the jar files are from Axis2 plugin directory. This
is causing the problem so please click "Ant Home" button on the right side and
setting up ant home such as "D:\java\ant\apache-ant-1.7.0" directory and click OK

Sunday 6 January 2008

Thursday 3 January 2008

replaceAll with special words

* replaceAll with special words

======================
public class MyTest {

public static void main(String args[]) {

String st = "\\";

st = st.replaceAll("\\\\","\\\\\\\\");

System.out.println(st);
}
}
======================================

Tuesday 1 January 2008