Nao esta validando

0 respostas
L

o que estou fazendo de errado?

Action

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

if(request.getParameter(“login”) == null){

return mapping.findForward(“success”);

}

LogFactory.getLog(this.getClass()).debug("Param Cliente = " + request.getParameter(“cliente”));

LogFactory.getLog(this.getClass()).debug("Param Username = " + request.getParameter(“username”));

LogFactory.getLog(this.getClass()).debug("Param Senha = " + request.getParameter(“senha”));

LoginCandidatoForm aForm = (LoginCandidatoForm) form;

LogFactory.getLog(this.getClass()).debug("Form Cliente = " + aForm.getCliente());

LogFactory.getLog(this.getClass()).debug("Form Username = " + aForm.getUsername());

LogFactory.getLog(this.getClass()).debug("Form Senha = " + aForm.getSenha());

Cliente cliente = ClienteBO.getClienteByApelido(request.getParameter(“cliente”));

if(StringUtils.isNotEmpty(request.getParameter(“login”))){

Candidato candidato = CandidatoService.login(cliente,

request.getParameter(“username”),

request.getParameter(“senha”));

if(candidato == null){

aForm.setFailed(true);

System.out.println(“candidato >>>” + candidato);

return mapping.findForward(“success”);

}

request.getSession().setAttribute(“cliente”, cliente);

request.getSession().setAttribute(“candidato”, candidato);

return mapping.findForward(“loginOk”);

}

return mapping.findForward(“success”);

}

}

Form

/**

  • @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)

*/

public ActionErrors validate(

ActionMapping mapping,

HttpServletRequest request) {

if(StringUtils.isEmpty(request.getParameter(“login”))){

return null;

}

ActionErrors errors = new ActionErrors();

if ((username == null) || (username.length() < 1)) {

errors.add(“username”, new ActionMessage(“error.username.required”));

System.out.println(“login >>>” + errors);

}

if ((senha == null) || (senha.length() < 1)) {

errors.add(“senha”, new ActionMessage(“error.senha.required”));

System.out.println(“senha >>>” + errors);

}

return errors;

}

JSP

<%@ page language=“java” %>

<%@ taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core” %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix=“bean” %>

<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix=“logic” %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix=“html” %>

<c:choose>

<c:when test="${sessionScope.cliente != null}">

<c:set var=“cliente” value="${sessionScope.cliente.apelido}"/>

</c:when>

<c:when test="${requestScope.cliente != null}">

<c:set var=“cliente” value="${requestScope.cliente}"/>

</c:when>

<c:otherwise>

<c:set var=“cliente” value="${param.cliente}"/>

</c:otherwise>

</c:choose>


<html:errors />


Login do Candidato

<html:form action="/candidato/login.do" method=“post”>

Login <html:text property=“username” size=“20” maxlength=“20” styleClass=“inputform” />

Senha <html:password property=“senha” size=“20” maxlength=“20” styleClass=“inputform” />


<html:submit property=“login” value=" Entrar " styleClass=“botaosubmit” />

</html:form>

Cadastrar novo usuario

STRUTS-CONFIG

<action

path="/candidato/login"

type=“peoplehr.struts.action.candidato.LoginAction”

input=“loginCandidato”

attribute=“form”

name=“loginCandidato”

scope=“request”>

Aplication Resources.properties

error.username.required=

  • Login!!
  • error.senha.required=

  • Senha!!
  • Criado 10 de maio de 2006
    Respostas 0
    Participantes 1