xhtml代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
<h:form>
<p:remoteCommand name="getInfo" action="#{beanUtil.getInfoMethod}"
oncomplete="onGetInfoMethodComplete(xhr,status,args)"/>
</h:form>
<script type="text/javascript" >
getInfo([{name:'param1',value:'param1'},{name:'param2',value:'param2'}]);
function onGetInfoMethodComplete(xhr,status,args){
alert(args.info);//alert "get info"
}
</script>

Java 代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package com.fenxiangz;
import javax.faces.context.FacesContext;
import org.primefaces.context.RequestContext;
public class BeanUtil {
public void getInfoMethod(){
Map<String, String> params = FacesContext
.getCurrentInstance().getExternalContext().getRequestParameterMap();
String param1 = params.get("param1");
String param2 = params.get("param2");
RequestContext.getCurrentInstance().addCallbackParam("info","get info");
return ;
}
}