我找到了一个关于如何在Richfaces中使用JSON的例子,但它不起作用......我不知道我是否错过了什么...... 代码如下:
<h:form id="form1" prependId="false">
<a4j:jsFunction
name="submitApplication"
action="#{jsFunctionBean.actionMethod}"
data="#{jsFunctionBean}"
oncomplete="processData(event.data)"
immediate="true">
</a4j:jsFunction>
<script type="text/javascript">
//example callback function with JSON data as argument
function processData(data) {
alert(data.test);
alert(data.name);
}
//call the ajax method from javascript
submitApplication();
</script>
</h:form>
和豆:
@ManagedBean(name =“jsFunctionBean”) @SessionScoped
public class JsFunctionBean {
/**
* Test String name
*/
private String name;
public String getName() { return this.name; }
public void setName(String name) { this.name = name; }
/**
* Test boolean
*/
private boolean test;
public boolean getTest() { return this.test; }
public void setTest(boolean test) { this.test = test; }
/**
* Action Method
*
* @return
*/
public String getActionMethod() {
this.test = true;
this.name = "Dave";
return null;
}
}
如果我运行此代码,则不会显示警报,并且我在浏览器上收到错误“'data'为null或不是对象”。 我是jsf 1.2和richfaces 3.3.3。
有什么想法吗?
提前感谢您的帮助。