Pessoal,
Bom Feriado a todos!
Estou começando com JSF (Richfaces) e estavafazendo uma telinha de login, e tem um modal, mas quando ele aparece o usuário digita as informações, mas quando faz o submit ele não "popula" o meu bean e retorna null.
Segue alguns códigos:
index.jsf
<?xml version="1.0" encoding="UTF-8"?>
<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:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link href="css/style.css" type="text/css" rel="stylesheet"/>
<title>#{msg['user.login']}</title>
</head>
<body background="images/background.jpg">
<style type="text/css">
.rich-message-marker img {
padding-right:7px;
}
.rich-message-label {
color:red;
}
</style>
<f:view>
<a4j:region>
<a4j:form id="login">
<rich:panel header="#{msg['user.login']}" style="width: 240px; margin: 0 auto">
<h:panelGrid columns="2" >
<h:outputLabel value="#{msg['user.user']}:" for="name"/>
<h:inputText id="name" value="#{userMB.user.username}" required="true" requiredMessage="#{msg['user.userRequired']}" autocomplete="off" maxlength="15" size="18" tabindex="1"/>
<h:outputLabel value="#{msg['user.password']}:"/>
<h:inputSecret id="password" value="#{userMB.user.password}" required="true" requiredMessage="#{msg['user.passwordRequired']}" maxlength="15" size="18" tabindex="2"/>
</h:panelGrid>
<a4j:commandLink id="forgetMyPasswordLink" immediate="true" value="#{msg['user.forgetmypassword']}">
<rich:componentControl for="panelMail" attachTo="forgetMyPasswordLink" operation="show" event="onclick"/>
</a4j:commandLink>
<rich:spacer width="10px"/>
<a4j:commandButton action="#{userMB.validateLogin}" onclick="this.disabled=true" oncomplete="this.disabled=false" value="#{msg ['general.ok']}" tabindex="3" type="submit" styleClass="button"/>
<br/><a4j:status id="text" startText="#{msg['action.inprogress']}"/>
<rich:messages layout="list">
<f:facet name="errorMarker">
<h:graphicImage value="images/error.gif" styleClass="pic" />
</f:facet>
</rich:messages>
</rich:panel>
<br/><br/>
</a4j:form>
</a4j:region>
<a4j:region>
<a4j:form id="forget" ajaxSubmit="true">
<rich:modalPanel id="panelMail" resizeable="false" autosized="true">
<f:facet name="header">
<h:panelGroup>
<h:outputText value="#{msg['user.forgetmypassword']}">
</h:outputText>
</h:panelGroup>
</f:facet>
<f:facet name="controls">
<h:panelGroup>
<h:graphicImage value="/images/close.png" id="hidelink" styleClass="hidelink"/>
<rich:componentControl for="panelMail" attachTo="hidelink" operation="hide" event="onclick"/>
</h:panelGroup>
</f:facet>
<h:panelGrid id="mailForm" columns="3">
<h:outputLabel value="#{msg['general.email']}"/>
<h:inputText id="mail" value="#{userMB.user.email}" maxlength="40" size="25" required="true" requiredMessage="#{msg['user.emailRequired']}">
<f:validateLength minimum="4" maximum="25"/>
</h:inputText>
<a4j:commandButton id="send" action="#{userMB.forgetMyPassword}" value="#{msg['general.send']}" type="submit" styleClass="button">
<rich:componentControl for="panelMail" attachTo="send" operation="hide" event="onclick"/>
</a4j:commandButton>
</h:panelGrid>
</rich:modalPanel>
</a4j:form>
</a4j:region>
</f:view>
</body>
</html>
meu bean simples:
[code]/**
*
*/
package org.noip.moviespace.jsf.managedbeans;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import org.noip.moviespace.model.User;
/**
-
@author gustavo.silva
-
@since 16/03/2009
-
@version 1.0
*/
public class UserMB {private User user = new User();
// gets e sets do User
/**
*-
@return
*/
public String validateLogin() {
if (user.validateUser()) {
// DAOFactory factory = new DAOFactory();
FacesContext facesContext = FacesContext.getCurrentInstance();
facesContext.getExternalContext().getSessionMap().put(“user”, user);
return “OK”;
} else {
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(“Usuário e/ou senha inválidos!”));
return null;
}
}
public String forgetMyPassword() {
System.out.println(user.getEmail());
return null;
} -
@return
}
[/code]
e meu model:
[code]/**
*
*/
package org.noip.moviespace.model;
import java.io.Serializable;
import java.sql.SQLException;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.validator.Email;
import org.hibernate.validator.NotEmpty;
import org.noip.moviespace.hibernate.DAO.DAOFactory;
import org.noip.moviespace.security.EncriptyPassword;
/**
- @author gustavo.silva
- @since 15/06/2008
-
@version 1.0
*/
@Entity
@Table(name = “TMS_EMPLOYEE_USERS”)
public class User implements Serializable {
// @Transient
// transient Logger logger = Logger.getLogger(User.class);
/**
*
*/
private static final long serialVersionUID = 4636756747700250066L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "EMPLOYEE_ID")
private Integer id;
@NotEmpty
@Column(name = "EMPLOYEE_USER_NAME", unique = true, nullable = false, length = 25)
private String username;
@NotEmpty
@Column(name = "EMPLOYEE_PASSWORD", unique = false, nullable = false, length = 50)
private String password;
@Email
@NotEmpty
@Column(name = "EMPLOYEE_EMAIL", unique = true, nullable = false, length = 40)
private String email;
@Column(name = "EMPLOYEE_ENABLED", unique = false, nullable = true)
private boolean enabled;
// gets e sets
public boolean validateUser() {
// logger.debug("Validating User");
boolean unique = false;
DAOFactory factory = new DAOFactory();
try {
unique = factory.getUserDao().validateLogin(this);
} catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
} finally {
factory.close();
}
return unique;
}
}[/code]
Obrigado pela ajuda de todos! 8)