ajaxTest.xhtml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:c="http://java.sun.com/jsp/jstl/core"> <h:head> <title>myjsf</title> <Meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> </h:head> <h:body> <body> <h:form id="form" style="padding:20px 0 20px 100px"> <div style="padding-left: 50px"> <h:commandButton id="post" style="padding:3px;width:100px;" value="提交响应" onclick="jsf.ajax.request(this,event,{execute:'form',render: 'after'}); return false;" actionListener="#{count.countIt}" /> </div> </h:form> <h:panelGroup id="after"> <div style="padding: 20px 0 0 100px"> <div style="padding: 0 0 10px 0">点击次数:#{count.count}</div> </div> </h:panelGroup> </body> </h:body> </html>
@ManagedBean(name = "count") @ViewScoped public class Count implements Serializable { /** * */ private static final long serialVersionUID = 9135869140010362113L; private int count = 0; public int getCount() { return count; } public void countIt() { count++; } }
原文链接:https://www.f2er.com/ajax/166520.html