Boa noite galera, estou iniciando meus estudos em JSF e esbarrei com um problema, meu <p:commandButton> não está executando o action…
Onde estou errando ? Eu procurei no fórum já, apliquei algumas “correções” mas ainda continuo com o problema. Segue os fontes:
login.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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>JSF 2.0 Hello World</title>
</h:head>
<h:outputStylesheet name="css/style.css"/>
<h:body>
<h:panelGroup layout="block" id="loginPanel">
<h:form>
<p:panelGrid columns="2" id="loginForm">
<f:facet name="header">Login</f:facet>
<h:outputLabel for="username" value="Username: *" />
<p:inputText id="username" value="#{LoginMBean.username}" label="Username" />
<h:outputLabel for="password" value="Password: *" />
<h:inputSecret id="password" value="#{LoginMBean.password}" required="true" label="Password"/>
<h:messages showDetail="true" showSummary="true" />
<f:facet name="footer">
<p:commandButton type="button" value="Save" icon="ui-icon-check" style="margin:0" action="#{LoginMBean.login}"/>
</f:facet>
</p:panelGrid>
</h:form>
</h:panelGroup>
</h:body>
</html>
Managed Bean: LoginMBean.java
package com.scheduler;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
public class LoginMBean implements Serializable {
private static final long serialVersionUID = -8307263806656386561L;
private String username;
private String password;
public String login(){
System.out.println("### Efetuando o LOGIN ###");
return "OK";
}
public String getUsername() {
System.out.println("### GETTING THE USERNAME ###");
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
<managed-bean>
<managed-bean-name>LoginMBean</managed-bean-name>
<managed-bean-class>com.scheduler.LoginMBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>login.xhtml</from-view-id>
<navigation-case>
<from-action>#{LoginMBean.login}</from-action>
<from-outcome>OK</from-outcome>
<to-view-id>menu.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
Estou usando o JBOSS EAP 6.x
O problema que o meu método login() do managed bean não é chamado!
Valeu pela ajuda desde já.