我在login.xhtml
下面的代碼:爲什麼commandButton actionListener不起作用?
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head><title>Login</title></h:head>
<h:body>
<h:form>
<p:commandButton id="loginBtn" value="Login" type="submit" actionListener="#{userMB.login}"/>
</h:form>
</h:body>
</html>
而且我有,我有以下豆:
@ManagedBean(name="userMB")
@RequestScoped
public class UsersManagedBean implements Serializable {
public void login(ActionEvent event) {
System.out.println("print here...");
}
}
我沒有得到消息,因爲印刷的login()
方法尚未調用。有什麼不對的嗎?
web.xml文件是:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID"
version="2.5">
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern> *.xhtml</url-pattern>
</servlet-mapping>
</web-app>
你把p:commandButton放在h:form裏面嗎?請顯示您的所有login.xhtml代碼。 – wittakarn 2014-10-28 02:54:54