struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Frank W. Zammetti" <fzli...@omnytex.com>
Subject Re: [S1] json and Action execute()
Date Tue, 22 Jan 2008 21:18:46 GMT
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


Mime
View raw message