You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by auz <f....@gmail.com> on 2008/01/22 22:09:19 UTC

[S1] json and Action execute()

i have a problem with struts action form execute and json. im using ext js as
mu ajax lib on client side and i need to retrive some departmentID and name
depenting on a combo box, the problem is i dont know how to put JSonObect so
that ext can see it here's my code any help is apritiated

on jsp page - this is ext js script

var departmentStore = new Ext.data.Store({
 reader: new Ext.data.JsonReader({
 totalProperty: 'total',
 root:'list'
 }, [{name: 'name'}])
})

var departmentCombo = new Ext.form.ComboBox({
 store:departmentStore,
 displayField:'name',
 valueField: 'name',
 hiddenName : 'city',
 typeAhead: true,
 mode: 'local',
 triggerAction: 'all',
 width:150,
 emptyText:'select a city',
 applyTo:'department',
 selectOnFocus:true
 });

studyProgramCombo.on('select', function () {
 departmentCombo.reset();
 departmentCombo.store.proxy= new
Ext.data.HttpProxy({disableCaching:false,url: selfURI +       
'JSONGetDepartment?studyProgram.json={"studyProgram":{"studyProgramID":' +    
studyProgramCombo.getValue() + '}}'});
 searchCityCombo.store.load();
});

//the rest of the jsp code is irelevant NOTE selfURI variable is set to
http://SERVERADDRESS/PROJECTNAME/

Struts Action execute code

JSONArray list = new JSONArray();
JSONObject obj = new JSONObject();  
while(result.next()) {
    obj.put("uid", result.getInt("departmentID"));
    obj.put("name", result.getString("name"));
    list.put(obj);
}
JSONObject rslt = new JSONObject();
rslt.put ("total", list.length());
rslt.put("list", list);
request.setAttribute("", rslt.toString()); //this name is unknown, i dont
know what to put here
return null;


what did i do wrong/ didnt do? tnx a lot
-- 
View this message in context: http://www.nabble.com/-S1--json-and-Action-execute%28%29-tp15028395p15028395.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S1] json and Action execute()

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Setting an attribute on the request object makes it available to JAVA
code, i.e., in a JSP, but ExtJS is Javascript running on the client.  I
believe, without knowing the specifics of what ExtJS expects, that what
you really want to do is write to the response stream the serialization of
your JSONObject.  In other words, the response coming back from the server
is text in the form of JSON (which will be present in the XHR object,
which I presume ExtJS is using under the covers to make the request).

Alternatively, you can do what you're trying to do in the Action, and then
forward to a JSP that reads the attribute and outputs the JSON... this is
probably a bit more work and overhead than you really need... writing to
the response stream in the Action and then returning null for the forward
does the trick.

Frank

-- 
Frank W. Zammetti
Author of "Practical DWR 2 Projects"
 (2008, Apress, ISBN 1-59059-941-1)
and "JavaScript, DOM Scripting and Ajax Projects"
 (2007, Apress, ISBN 1-59059-816-4)
and "Practical Ajax Projects With Java Technology"
 (2006, Apress, ISBN 1-59059-695-1)
Java Web Parts - http://javawebparts.sourceforge.net
 Supplying the wheel, so you don't have to reinvent it!

On Tue, January 22, 2008 4:09 pm, auz wrote:
>
> i have a problem with struts action form execute and json. im using ext js
> as
> mu ajax lib on client side and i need to retrive some departmentID and
> name
> depenting on a combo box, the problem is i dont know how to put JSonObect
> so
> that ext can see it here's my code any help is apritiated
>
> on jsp page - this is ext js script
>
> var departmentStore = new Ext.data.Store({
>  reader: new Ext.data.JsonReader({
>  totalProperty: 'total',
>  root:'list'
>  }, [{name: 'name'}])
> })
>
> var departmentCombo = new Ext.form.ComboBox({
>  store:departmentStore,
>  displayField:'name',
>  valueField: 'name',
>  hiddenName : 'city',
>  typeAhead: true,
>  mode: 'local',
>  triggerAction: 'all',
>  width:150,
>  emptyText:'select a city',
>  applyTo:'department',
>  selectOnFocus:true
>  });
>
> studyProgramCombo.on('select', function () {
>  departmentCombo.reset();
>  departmentCombo.store.proxy= new
> Ext.data.HttpProxy({disableCaching:false,url: selfURI +
> 'JSONGetDepartment?studyProgram.json={"studyProgram":{"studyProgramID":' +
> studyProgramCombo.getValue() + '}}'});
>  searchCityCombo.store.load();
> });
>
> //the rest of the jsp code is irelevant NOTE selfURI variable is set to
> http://SERVERADDRESS/PROJECTNAME/
>
> Struts Action execute code
>
> JSONArray list = new JSONArray();
> JSONObject obj = new JSONObject();
> while(result.next()) {
>     obj.put("uid", result.getInt("departmentID"));
>     obj.put("name", result.getString("name"));
>     list.put(obj);
> }
> JSONObject rslt = new JSONObject();
> rslt.put ("total", list.length());
> rslt.put("list", list);
> request.setAttribute("", rslt.toString()); //this name is unknown, i dont
> know what to put here
> return null;
>
>
> what did i do wrong/ didnt do? tnx a lot
> --
> View this message in context:
> http://www.nabble.com/-S1--json-and-Action-execute%28%29-tp15028395p15028395.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S1] json and Action execute()

Posted by nuwan chandrasoma <my...@gmail.com>.
Hi,

I haven't used ExtJS., but we i have done is i just writhe the json string
to the output stream and from my js i convert it to JSON and used it. i used
Dojo

Thanks,

Nuwan
(http://code.google.com/p/struts2-ssl-plugin/)

On Jan 23, 2008 12:26 AM, auz <f....@gmail.com> wrote:

>
> this is struts 1.3.9 not 2.x, it can be done over json plugin for struts
> 2.x,
> or can it?
>
> jmitchell wrote:
> >
> > Take a look at this page:
> >  http://cwiki.apache.org/S2PLUGINS/json-plugin.html
> >
> > (Specifically "Root Object")
> >
> > It should match your result type name
> >
> >
> >
> > On Jan 22, 2008 4:09 PM, auz <f....@gmail.com> wrote:
> >>
> >> i have a problem with struts action form execute and json. im using ext
> >> js as
> >> mu ajax lib on client side and i need to retrive some departmentID and
> >> name
> >> depenting on a combo box, the problem is i dont know how to put
> JSonObect
> >> so
> >> that ext can see it here's my code any help is apritiated
> >>
> >> on jsp page - this is ext js script
> >>
> >> var departmentStore = new Ext.data.Store({
> >>  reader: new Ext.data.JsonReader({
> >>  totalProperty: 'total',
> >>  root:'list'
> >>  }, [{name: 'name'}])
> >> })
> >>
> >> var departmentCombo = new Ext.form.ComboBox({
> >>  store:departmentStore,
> >>  displayField:'name',
> >>  valueField: 'name',
> >>  hiddenName : 'city',
> >>  typeAhead: true,
> >>  mode: 'local',
> >>  triggerAction: 'all',
> >>  width:150,
> >>  emptyText:'select a city',
> >>  applyTo:'department',
> >>  selectOnFocus:true
> >>  });
> >>
> >> studyProgramCombo.on('select', function () {
> >>  departmentCombo.reset();
> >>  departmentCombo.store.proxy= new
> >> Ext.data.HttpProxy({disableCaching:false,url: selfURI +
> >>
> 'JSONGetDepartment?studyProgram.json={"studyProgram":{"studyProgramID":'
> >> +
> >> studyProgramCombo.getValue() + '}}'});
> >>  searchCityCombo.store.load();
> >> });
> >>
> >> //the rest of the jsp code is irelevant NOTE selfURI variable is set to
> >> http://SERVERADDRESS/PROJECTNAME/
> >>
> >> Struts Action execute code
> >>
> >> JSONArray list = new JSONArray();
> >> JSONObject obj = new JSONObject();
> >> while(result.next()) {
> >>     obj.put("uid", result.getInt("departmentID"));
> >>     obj.put("name", result.getString("name"));
> >>     list.put(obj);
> >> }
> >> JSONObject rslt = new JSONObject();
> >> rslt.put ("total", list.length());
> >> rslt.put("list", list);
> >> request.setAttribute("", rslt.toString()); //this name is unknown, i
> dont
> >> know what to put here
> >> return null;
> >>
> >>
> >> what did i do wrong/ didnt do? tnx a lot
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/-S1--json-and-Action-execute%28%29-tp15028395p15028395.html
> >> Sent from the Struts - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
> >
> >
> > --
> > James Mitchell
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/-S1--json-and-Action-execute%28%29-tp15028395p15028765.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [S1] json and Action execute()

Posted by auz <f....@gmail.com>.
this is struts 1.3.9 not 2.x, it can be done over json plugin for struts 2.x,
or can it?

jmitchell wrote:
> 
> Take a look at this page:
>  http://cwiki.apache.org/S2PLUGINS/json-plugin.html
> 
> (Specifically "Root Object")
> 
> It should match your result type name
> 
> 
> 
> On Jan 22, 2008 4:09 PM, auz <f....@gmail.com> wrote:
>>
>> i have a problem with struts action form execute and json. im using ext
>> js as
>> mu ajax lib on client side and i need to retrive some departmentID and
>> name
>> depenting on a combo box, the problem is i dont know how to put JSonObect
>> so
>> that ext can see it here's my code any help is apritiated
>>
>> on jsp page - this is ext js script
>>
>> var departmentStore = new Ext.data.Store({
>>  reader: new Ext.data.JsonReader({
>>  totalProperty: 'total',
>>  root:'list'
>>  }, [{name: 'name'}])
>> })
>>
>> var departmentCombo = new Ext.form.ComboBox({
>>  store:departmentStore,
>>  displayField:'name',
>>  valueField: 'name',
>>  hiddenName : 'city',
>>  typeAhead: true,
>>  mode: 'local',
>>  triggerAction: 'all',
>>  width:150,
>>  emptyText:'select a city',
>>  applyTo:'department',
>>  selectOnFocus:true
>>  });
>>
>> studyProgramCombo.on('select', function () {
>>  departmentCombo.reset();
>>  departmentCombo.store.proxy= new
>> Ext.data.HttpProxy({disableCaching:false,url: selfURI +
>> 'JSONGetDepartment?studyProgram.json={"studyProgram":{"studyProgramID":'
>> +
>> studyProgramCombo.getValue() + '}}'});
>>  searchCityCombo.store.load();
>> });
>>
>> //the rest of the jsp code is irelevant NOTE selfURI variable is set to
>> http://SERVERADDRESS/PROJECTNAME/
>>
>> Struts Action execute code
>>
>> JSONArray list = new JSONArray();
>> JSONObject obj = new JSONObject();
>> while(result.next()) {
>>     obj.put("uid", result.getInt("departmentID"));
>>     obj.put("name", result.getString("name"));
>>     list.put(obj);
>> }
>> JSONObject rslt = new JSONObject();
>> rslt.put ("total", list.length());
>> rslt.put("list", list);
>> request.setAttribute("", rslt.toString()); //this name is unknown, i dont
>> know what to put here
>> return null;
>>
>>
>> what did i do wrong/ didnt do? tnx a lot
>> --
>> View this message in context:
>> http://www.nabble.com/-S1--json-and-Action-execute%28%29-tp15028395p15028395.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 
> 
> -- 
> James Mitchell
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-S1--json-and-Action-execute%28%29-tp15028395p15028765.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [struts] [S1] json and Action execute()

Posted by James Mitchell <jm...@gmail.com>.
Doh!  Sorry.

On Jan 22, 2008 4:21 PM, Dale Newfield <Da...@newfield.org> wrote:
> James Mitchell wrote:
> > Take a look at this page:
> >  http://cwiki.apache.org/S2PLUGINS/json-plugin.html
>
> The OP specified struts1 in the subject.
>
> -Dale
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
James Mitchell

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [struts] [S1] json and Action execute()

Posted by Dale Newfield <Da...@Newfield.org>.
James Mitchell wrote:
> Take a look at this page:
>  http://cwiki.apache.org/S2PLUGINS/json-plugin.html

The OP specified struts1 in the subject.

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S1] json and Action execute()

Posted by James Mitchell <jm...@gmail.com>.
Take a look at this page:
 http://cwiki.apache.org/S2PLUGINS/json-plugin.html

(Specifically "Root Object")

It should match your result type name



On Jan 22, 2008 4:09 PM, auz <f....@gmail.com> wrote:
>
> i have a problem with struts action form execute and json. im using ext js as
> mu ajax lib on client side and i need to retrive some departmentID and name
> depenting on a combo box, the problem is i dont know how to put JSonObect so
> that ext can see it here's my code any help is apritiated
>
> on jsp page - this is ext js script
>
> var departmentStore = new Ext.data.Store({
>  reader: new Ext.data.JsonReader({
>  totalProperty: 'total',
>  root:'list'
>  }, [{name: 'name'}])
> })
>
> var departmentCombo = new Ext.form.ComboBox({
>  store:departmentStore,
>  displayField:'name',
>  valueField: 'name',
>  hiddenName : 'city',
>  typeAhead: true,
>  mode: 'local',
>  triggerAction: 'all',
>  width:150,
>  emptyText:'select a city',
>  applyTo:'department',
>  selectOnFocus:true
>  });
>
> studyProgramCombo.on('select', function () {
>  departmentCombo.reset();
>  departmentCombo.store.proxy= new
> Ext.data.HttpProxy({disableCaching:false,url: selfURI +
> 'JSONGetDepartment?studyProgram.json={"studyProgram":{"studyProgramID":' +
> studyProgramCombo.getValue() + '}}'});
>  searchCityCombo.store.load();
> });
>
> //the rest of the jsp code is irelevant NOTE selfURI variable is set to
> http://SERVERADDRESS/PROJECTNAME/
>
> Struts Action execute code
>
> JSONArray list = new JSONArray();
> JSONObject obj = new JSONObject();
> while(result.next()) {
>     obj.put("uid", result.getInt("departmentID"));
>     obj.put("name", result.getString("name"));
>     list.put(obj);
> }
> JSONObject rslt = new JSONObject();
> rslt.put ("total", list.length());
> rslt.put("list", list);
> request.setAttribute("", rslt.toString()); //this name is unknown, i dont
> know what to put here
> return null;
>
>
> what did i do wrong/ didnt do? tnx a lot
> --
> View this message in context: http://www.nabble.com/-S1--json-and-Action-execute%28%29-tp15028395p15028395.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
James Mitchell

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org