-
1. Send JSON as param using a4j:jsFunction
nbelaevski Mar 24, 2011 9:54 AM (in response to satyakatti)Hi Satya,
No it's not possible to send JSON object out of the box.
It is enough to define <a4j:jsFunction> tag, nothing else required.
-
2. Send JSON as param using a4j:jsFunction
satyakatti Mar 25, 2011 12:40 AM (in response to nbelaevski)Hi Nick,
I tried few things yesterday and it is possible to send the JSON object. Also you can reconstruct the object at bean.
Though not straightforward but still possible.
Below code calls a javascript function which internally calls a4j:jsFunction for sending JSON...
<a4j:form>
<a4j:commandButton value="Click Me..." onclick='callMe();'/>
<a4j:jsFunction name="updateCart">
<a4j:actionparam name="json" assignTo="#{partManagementBean.jsonObject}"/>
</a4j:jsFunction>
</a4j:form>
JS function converts JSON to text
function callMe() {
var myJSON = {"firstName" : "Satya", "lastName" : "K"};
var jsonText = JSON.stringify(myJSON);
updateCart(jsonText);
}
Reconstructing the JSON string to Object...
public void setJsonObject(Object jsonObject) throws JSONException {
JSONObject richObj = new JSONObject(jsonObject.toString());
LOGGER.info("richfaces jsonObject : " + richObj.getString("firstName"));
this.jsonObject = jsonObject;
}
Regards,
Satya
-
3. Send JSON as param using a4j:jsFunction
nbelaevski Mar 25, 2011 5:27 AM (in response to satyakatti)Yes, possible in this way.