An action has this validation config:
Campo obrigatório
Campo obrigatório
[a-z]+
Digite apenas letras minúsculas. Não são
permitidos espaços,
números, nem caracteres acentuados.
The validation works fine, except that the field error messages are
not getting cleared when the user fills the fields correctly in the
second submit.
The procedure is:
1. Submit the form with all fields empty;
(Struts shows the validation error messages correctly.)
2. Fill all fields with good values and submit again.
(Struts duplicates the messages right above the previous ones.)
And as you submit the form over and over again, Struts keeps
invalidating the fields, duplicating the error messages. I'm using
Struts 2.0.6.
-8-<- struts.xml (excerpt for that action) -8-<-
/jsp/private/usuario-form.jsp
listaDeUsuarios
-8-<- the action -8-<-
public class UsuarioFormAction extends PrevaylerAction {
private static final long serialVersionUID = 1L;
private int id = 0;
private String nome;
private Perfil perfil;
private String identificacao;
private String senha;
private String confirmacaoDeSenha;
public Set getPerfis() {
return contexto().getPerfis();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public int getPerfil() {
return perfil.getId();
}
public void setPerfil(int id) throws Exception {
PesquisaDePerfilPorIdQuery pesquisa = new
PesquisaDePerfilPorIdQuery();
pesquisa.setId(id);
perfil = (Perfil) prevayler().execute(pesquisa);
}
public String getIdentificacao() {
return identificacao;
}
public void setIdentificacao(String identificacao) {
this.identificacao = identificacao;
}
public void setSenha(String senha) {
this.senha = senha;
}
public void setConfirmacaoDeSenha(String confirmacaoDeSenha) {
this.confirmacaoDeSenha = confirmacaoDeSenha;
}
public String input() throws Exception {
if (id != 0) {
PesquisaDeUsuarioPorIdQuery pesquisa = new
PesquisaDeUsuarioPorIdQuery();
pesquisa.setId(id);
Usuario usuario = (Usuario)
prevayler().execute(pesquisa);
if (usuario == null)
return ERROR;
nome = usuario.getNome();
perfil = usuario.getPerfil();
identificacao = usuario.getIdentificacao();
}
return INPUT;
}
public String salvar() throws Exception {
if (senha.compareTo(confirmacaoDeSenha) == 0) {
if (id == 0) {
if (senha.length() > 0)
criar();
else {
addActionMessage("Digite uma senha para o
novo usuário.");
return INPUT;
}
} else
modificar();
} else {
addActionMessage("As senhas não conferem. Digite-as
novamente.");
return INPUT;
}
return SUCCESS;
}
private void modificar() {
ModificacaoDeUsuarioTransaction modificacao = new
ModificacaoDeUsuarioTransaction();
modificacao.setId(id);
modificacao.setNome(nome);
modificacao.setPerfil(perfil);
modificacao.setIdentificacao(identificacao);
if (senha.length() > 0)
modificacao.setSenha(senha);
prevayler().execute(modificacao);
}
private void criar() throws Exception {