我找到了一个关于如何将 JSON 与 Richfaces 一起使用的示例,但它不起作用……我不知道我是否遗漏了什么……这里的代码:
<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' is null or not an object”。我使用的是 jsf 1.2 和 richfaces 3.3.3。
任何想法?
在此先感谢您的帮助。