Olá a todos,
Estou tentando fazer um form para o cadastro de um aluno ao sistema, uso o webwork e para persistência o hibernate, sempre me da um erro dizendo que os atributos estão vazios, vejam os meus códigos:
Classe CadastraAluno.java
/**
*
*/
package br.com.sistema.action;
import br.com.sistema.model.Aluno;
import br.com.sistema.model.AlunoDAO;
import com.opensymphony.xwork.ActionSupport;
/**
* @author Paulo
*
*/
public class CadastraAluno extends ActionSupport {
private Aluno a = new Aluno();
AlunoDAO dao = new AlunoDAO();
public String execute() throws Exception {
dao.save(a);
return "SUCCESS";
}
public void setAluno (Aluno aluno){
this.a = aluno;
}
public Aluno getAluno(){
return this.a;
}
}
xwork.xml
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN"
"http://www.opensymphony.com/xwork/xwork-1.0.dtd">
<xwork>
<!-- Include webwork defaults (from WebWork JAR). -->
<include file="webwork-default.xml" />
<!-- Configuration for the default package. -->
<package name="default" extends="webwork-default">
<action name="CadastraAluno" class="br.com.sistema.action.CadastraAluno">
<result name="success" type="dispatcher">success.jsp</result>
</action>
</package>
</xwork>
O meu arquivo jsp com o form
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>::. Cadastro de Alunos .::</title>
<style type="text/css">
<!--
.style34 {font-size: 9px}
.style35 {
font-weight: bold;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
}
.style37 {font-weight: bold; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px; }
-->
</style>
</head>
<body>
<form action="CadastraAluno.action" method="post" name="Cadastro" id="Cadastro">
<table width="438" border="0" align="center" cellpadding="0" cellspacing="0">
<tr bgcolor="#CCCCCC">
<td height="30" colspan="2"><div align="center" class="style34"><span class="style37">Cadastro de Alunos </span></div></td>
</tr>
<tr bgcolor="#FFFFCC">
<td width="99" height="30"><div align="right" class="style35">Ra </div></td>
<td width="339" height="30"><input name="aluno.matricula" type="text" id="aluno.matricula" size="15"></td>
</tr>
<tr bgcolor="#FFFFCC">
<td width="99" height="30"><div align="right" class="style35">Nome </div></td>
<td height="30"><input name="aluno.nome" type="text" id="aluno.nome" size="50"></td>
</tr>
<tr bgcolor="#FFFFCC">
<td width="99" height="30"><div align="right" class="style35">E-mail </div></td>
<td height="30"><input name="aluno.email" type="text" id="aluno.email" size="40"></td>
</tr>
<tr bgcolor="#FFFFCC">
<td width="99" height="30"><div align="right" class="style35">Curso </div></td>
<td height="30"><select name="aluno.curso" id="aluno.curso">
<option selected>Sistemas de Informação</option>
<option>Administração</option>
</select></td>
</tr>
<tr bgcolor="#FFFFCC">
<td width="99" height="30"><div align="right" class="style35">Senha </div></td>
<td height="30"><input name="aluno.senha" type="password" id="aluno.senha"></td>
</tr>
<tr bgcolor="#FFFFCC">
<td width="99" height="30"><div align="right" class="style35">Redigite Senha </div></td>
<td height="30"><input name="retype_pass" type="password" id="retype_pass"></td>
</tr>
<tr bgcolor="#FFFFCC">
<td width="99" height="30"> </td>
<td height="30"><input type="submit" name="Submit" value="Cadastrar"></td>
</tr>
<tr bgcolor="#CCCCCC">
<td height="30" colspan="2"> </td>
</tr>
</table>
</form>
</body>
</html>
Fiz um teste já, na action de cadastro eu mesmo setei os atributos da classe Aluno no código, dae da certo, o q parece é que ele não pega os atributos do form.
Bom se alguém souber.
Atenciosamente,
Paulo

