-
1. Re: store xml string in a hidden field?
sergeysmirnov Mar 19, 2007 3:16 PM (in response to snod0g)It looks for me that you include "the part of the solution" to your question. This solution does not seem to me optimal.
Is it important for you to use exactly a "hidden field" and have those three steps to update something in the browser? -
2. Re: store xml string in a hidden field?
alexsmirnov Mar 19, 2007 3:19 PM (in response to snod0g)You can use 'data' attribute for return any Java object to 'oncomplete' function :
.............. <a4j:commandButton action="#{bean.action}" data="#{bean.xmlString}" oncomplete="myfunction(data)" /> <script> function myfunction(xmlString){...} </script> .........
There 'bean' is You server-side code part.
action() method should fill xmlString bean property, accessed by methodpublic String getXmlString() {...};
and 'myfunction' is a client-side JavaScript function.
By default data object will be serialised by JSON , as far as you can use most of Java types : primitives, String,arrays, Collections, Map or any JavaBean . -
3. Re: store xml string in a hidden field?
snod0g Mar 20, 2007 12:34 PM (in response to snod0g)FYI the reason why I need the data passed to a javascript function is so that I can use Jack Slocum's YUI-EXT Datagrid: http://www.yui-ext.com/deploy/yui-ext/docs/
im curious if anyone here has tried integrating ajax4jsf with yui-ext widgets? -
4. Re: store xml string in a hidden field?
snod0g Mar 20, 2007 12:42 PM (in response to snod0g)alex,
thanks for the reply! i really appreciate it.
in your example you pass the data variable to the javascript function myfunction(). but in the documentation it says to use this.dataSerialized (on default with JSON) data passed on the client by a developer on AJAX request. It's accessible via this.data
does both work?
also, you said:By default data object will be serialised by JSON , as far as you can use most of Java types : primitives, String,arrays, Collections, Map or any JavaBean .
can you explain this a little more? i understand that you are saying it will be serialized as JSON, but how are you saying that there is a way to have it returned as other formats as well? (such as string, arrays, etc?)
thank you! -
5. Re: store xml string in a hidden field?
sergeysmirnov Mar 20, 2007 2:32 PM (in response to snod0g)with a4j:jsFunction you can call Ajax from javascript and then call other javascript with returned data. So, no button or hidden field are required
-
6. Re: store xml string in a hidden field?
alexsmirnov Mar 20, 2007 4:38 PM (in response to snod0g)JSON serialisation/deserialisation is done transparently for developer :
Java primitives or String will be converted to JavaScript primitives.
Java arrays or Collections will be converted to JavaScript array :
Java :
int[] data = { 1,2,3};
JavaScript :
data[1] -> 1
data[2] -> 2
...
List data = new ArrayList -> JavaScript array.
Maps and Java beans will be converted to JavaScript hash :
data.get("foo" ) -> data['foo'] or data.foo
data.getFoo() -> data['foo'] or data.foo
reference to this.data is a documentation bug. -
7. Re: store xml string in a hidden field?
ilya_shaikovsky Mar 21, 2007 5:14 AM (in response to snod0g)Documentation issue fixed. Sorry for inconvenience, it will be republished soon.