PDA

View Full Version : How i connect java code with Sencha Touch ! ! !



sunder
19 Aug 2010, 2:38 AM
Hi ,
I am new to use sencha touch,

I have a website which is built in Java/J2EE and Struts framework. I am looking to build the mobile webapp using Sencha Touch. But i want to know if and how we can connect our back-end Java application with a Sencha Touch based front end.


so please assist me and give me guideline for this.


Regards...

Sunder

Condor
19 Aug 2010, 3:02 AM
Yes, you can, but in most cases you will want to change the reponse of the server from a html page to JSON data (the simplest way to do this is to use json-taglib in your response .jsp).

sunder
19 Aug 2010, 4:10 AM
So,

Please tell me how i will get started to write code with sencha touch.

Thanks

Sunder

sunder
3 Sep 2010, 3:33 AM
Hi,

I am new to extjs. I want to make a web application based on EXTJS application with struts1.2.
My problem is that:-

I have a page (html) which have some textfield and create this with FormPanel. (register.js)
Textfields are firstname, lastname, city, state, country.
I have action class (RegisterAction.java)
I got all textfied value and perform some business logic inside action class after getting those values I want to display those values on the page.

So please anybody tell me the possible way how I can display those values on the page.

I tried it on my end with the help of JSON.
I am writing some code of my point of view which I had tried, please anybody tell me how much this code is fine. If I am wrong please give me suggestions how I can display these values on page.
I got all textfied value in action class and I add these values in Arraylist and that Arraylist I convert into json object.
1.RegisterAction.java
List list=new Arraylist ();
list.add(firstname);
list.add(lastname);
list.add(email);
list.add(state);
list.add(city);
list.add(country);

JSONArray jsonArray = JSONArray.fromObject (list);
String showJsonObject=jsonArray.toString ();

PrintWriter pw=response.getWriter ();
pw.write (showJsonObject);

Now I want display that json object on other page (showData.js).
I read EXTJS API through this I understood that we can do it through Ext.data.Store and Ext.data.JsonReader.

I tried it on my code but I am unable to display json objects on the page.

2.ShowData.js
Ext.onReady(function()
{
var myReader = new Ext.data.JsonReader(
{root: 'showjsonObject'}, ['firstname','lastname','email','city','state','country']
);

var dataFromServer = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url:'/register.do'}),
reader: myReader
});


dataFromServer.on('load', function() {


var grid = new Ext.grid.GridPanel({
store: dataFromServer,
columns: [
{header: 'FirstName', width: 90, sortable: true, dataIndex: 'firstname'},
{header: 'LastName', width: 90, sortable: true, dataIndex: 'lastname'},
{header: 'Email', width: 90, sortable: true, dataIndex: 'email'},
{header: 'City', width: 90, sortable: false, dataIndex: 'city'},
{header: 'State', width: 90, sortable: false, dataIndex: 'state'},
{header: 'Country', width: 90, sortable: false, dataIndex: 'country'}
]
});
});

dataFromServer.load();
});
Can anybody tell me what code should be written inside show.js?
What code should be needed to display json object on the page.

Anybody please give me sample code and some guidance so that I can make application.

sunder
3 Sep 2010, 4:04 AM
Hi,

I am new to extjs. I want to make a web application based on EXTJS application with struts1.2.
My problem is that:-

I have a page (html) which have some textfield and create this with FormPanel. (register.js)
Textfields are firstname, lastname, city, state, country.
I have action class (RegisterAction.java)
I got all textfied value and perform some business logic inside action class after getting those values I want to display those values on the page.

So please anybody tell me the possible way how I can display those values on the page.

I tried it on my end with the help of JSON.
I am writing some code of my point of view which I had tried, please anybody tell me how much this code is fine. If I am wrong please give me suggestions how I can display these values on page.
I got all textfied value in action class and I add these values in Arraylist and that Arraylist I convert into json object.
1.RegisterAction.java
List list=new Arraylist ();
list.add(firstname);
list.add(lastname);
list.add(email);
list.add(state);
list.add(city);
list.add(country);

JSONArray jsonArray = JSONArray.fromObject (list);
String showJsonObject=jsonArray.toString ();

PrintWriter pw=response.getWriter ();
pw.write (showJsonObject);

Now I want display that json object on other page (showData.js).
I read EXTJS API through this I understood that we can do it through Ext.data.Store and Ext.data.JsonReader.

I tried it on my code but I am unable to display json objects on the page.

2.ShowData.js
Ext.onReady(function()
{
var myReader = new Ext.data.JsonReader(
{root: 'showjsonObject'}, ['firstname','lastname','email','city','state','country']
);

var dataFromServer = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url:'/register.do'}),
reader: myReader
});


dataFromServer.on('load', function() {


var grid = new Ext.grid.GridPanel({
store: dataFromServer,
columns: [
{header: 'FirstName', width: 90, sortable: true, dataIndex: 'firstname'},
{header: 'LastName', width: 90, sortable: true, dataIndex: 'lastname'},
{header: 'Email', width: 90, sortable: true, dataIndex: 'email'},
{header: 'City', width: 90, sortable: false, dataIndex: 'city'},
{header: 'State', width: 90, sortable: false, dataIndex: 'state'},
{header: 'Country', width: 90, sortable: false, dataIndex: 'country'}
]
});
});

dataFromServer.load();
});
Can anybody tell me what code should be written inside show.js?
What code should be needed to display json object on the page.

Anybody please give me sample code and some guidance so that I can make application

Thanx in Advance......

dlamotta
22 Dec 2011, 8:15 AM
Hey Sunder... try GWT4Touch. Both versions 1.1.1 and 2.0 (dev preview) are available today, and you'll be able to do your front-end in Java, and reuse your Java backed by tapping into GWT.

Check out a live demo at gwt4touch2.appspot.com, or a video we posted on DZone (http://java.dzone.com/videos/intro-gwt4touch-20).

You can get the package from www.emitrom.com/gwt4touch (http://www.emitrom.com/gwt4touch)

Best of luck!

cilohaidem
8 Jan 2012, 12:54 PM
dlmotta - tnx! this is great news!