[color=blue]OK, amigo![/color]
Olá!
Pessoal estou começando a aprender Struts e não consigo fazer o Update...
Bom, é um sistema de login de usuários!
Tenho um JSP que busca o Usuário pelo seu login e joga os dados desse Usuário em outro JSP!
JSP de busca:
<html:html locale="true">
<div id="tela">
<h3><bean:message key="projeto.titulo"/></h3>
<font color="blue">
<p><b><bean:message key="projeto.subtituloUser"/></b></p>
</font>
<html:form method="post" action="consultaAtualizar">
<tt>
Login do Usuário ........: <html:text property="usuario.login"/>
<b><html:errors property="login"/></b>
<b><html:errors property="loginInesistente"/></b>
<br/><br/>
<html:submit value="Consulta Usuário"/>
<html:reset value="Apagar"/>
<br/><br/>
<fieldset style="width: 15%" >
<html:link action="gerenciar" ><h5><b>Voltar ao Menu</b></h5></html:link>
</fieldset>
</tt>
</html:form>
</div>
</html:html>
Tenhu um Form que faz a validação e uma action que busca o usuário e manda para o outro JSP
O outro JSP que recebe os dados:
"u2 é o objeto que está vindo da ação que fez a busca"Usuario u2 = (Usuario) request.getAttribute("usuario");
<html:html locale="true">
<div id="tela">
<h3><bean:message key="projeto.titulo"/></h3>
<font color="blue">
<p><b><bean:message key="projeto.subtituloUser"/></b></p>
</font>
<html:form method="post" action="atualizar">
<tt>
<p><b>Formulário de Atualização de Usuários</b></p>
<br>
<font color="red"><h4>${msg}</h4></font>
Nome do Usuário .........: <html:text property="usuario.nome" value="<%=u2.getNome() %>" size="20"/>
<b><html:errors property="nome"/></b>
<br/><br/>
Login do Usuário ........: <html:text property="usuario.login" value="<%=u2.getLogin() %>" size="20"/>
<b><html:errors property="login"/></b>
<b><html:errors property="usandologin"/></b>
<br/><br/>
Informe sua Senha .......: <html:password property="usuario.senha" value="<%=u2.getSenha() %>" size="22"/>
<b><html:errors property="senha"/></b>
<br/><br/>
Confirme sua Senha.......: <html:password property="usuario.confirmaSenha" value="<%= u2.getConfirmaSenha() %>" size="22"/>
<b><html:errors property="confirmaSenha"/></b>
<b><html:errors property="confirmaSenha2"/></b>
<br/><br/>
Informe seu perfil.......: <html:text property="usuario.perfil" value="<%=u2.getPerfil()%>" size="20"/>
<b><html:errors property="perfil"/></b>
<br/><br/>
<html:submit value="Atualizar Usuário"/>
<html:reset value="Apagar"/>
<br/><br/>
<fieldset style="width: 15%" >
<html:link action="gerenciar" ><h5><b>Voltar ao Menu</b></h5></html:link>
</fieldset>
</tt>
</html:form>
</div>
</html:html>
tenho um form que valida esses dados...
Form....private Usuario usuario;
UsuarioDao d = new UsuarioDao();
public AtualizarUsuarioForm() {
usuario = new Usuario();
}
public Usuario getUsuario() {
return usuario;
}
public void setUsuario(Usuario usuario) {
this.usuario = usuario;
}
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
try {
if (usuario.getNome().length() < 1) {
errors.add("nome", new ActionMessage("projeto.campo"));
}
if (usuario.getLogin().length() < 1) {
errors.add("login", new ActionMessage("projeto.campo"));
} else {
UsuarioDao d = new UsuarioDao();
try {
if (d.loginExistente(usuario.getLogin())) {
errors.add("usandologin", new ActionMessage("projeto.erroCadastrar"));
}
} catch (Exception e) {
errors.add("usandologin", new ActionMessage(e.getMessage()));
}
}
if (usuario.getSenha().length() < 1) {
errors.add("senha", new ActionMessage("projeto.campo"));
}
if(!usuario.getSenha().equals(usuario.getConfirmaSenha())){
errors.add("confirmaSenha", new ActionMessage("projeto.Csenha"));
}else if(usuario.getConfirmaSenha().length()<1){
errors.add("confirmaSenha2", new ActionMessage("projeto.campo"));
}
if (usuario.getPerfil().length() < 1) {
errors.add("perfil", new ActionMessage("projeto.campo"));
}
} catch (Exception e) {
}
return errors;
}
}
e tenho uma ação que manda para o Hibernate atualizar
Acão atualizar:
AtualizarUsuarioForm f = (AtualizarUsuarioForm) form;
Usuario u = (Usuario)f.getUsuario();
try {
ud.atualizar(u);
request.setAttribute("msg", "Dados Atualizados com Sucesso!");
} catch (Exception e) {
request.setAttribute("msg", "Erro: " + e.getMessage());
}
return mapping.findForward(SUCCESS);
}
}
Quando mando Atualizar da esse Erro Chato...
type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: java.lang.NullPointerException
root cause
java.lang.NullPointerException