rodrigo.bossini 28 de jul. de 2009
arm.jr:
Boa tarde.
Chamo o método ‘cadastrar’, da action.
Só que acaba passando pelo mesmo método 2 vezes, causando erro.
Por que isso acontece, se algum problema no mapeamento?
Mapeamento :
<action path="/ENTR/Cadastrar" name="visaoProcedimento"
type="br.com.apresentacao.action.ControladorProcedimento"
scope="request" validate="true" input="/do/ENTR/Proc?method=carregarTela" parameter="method">
<forward name="success" path="tela.confirmacao"/>
<forward name="telaInicialInsercao" path="/do/ENTR/Proc?method=carregarTela"/>
<forward name="error" path="error.page"/>
</action>
O mapeamento me parece correto…posta o código da action e do form.
arm.jr 28 de jul. de 2009
Logo abaixo.
Método de chamado na action
----------------------------------------------------------------
public ActionForward cadastrar ( ActionMapping mapping , ActionForm actionForm , HttpServletRequest request ,
HttpServletResponse response ) {
try {
VisaoProcedimento form = ( VisaoProcedimento ) actionForm ;
form . setTipoOperacao ( ETipoOperacao . INCLUIR );
ActionErrors errors = form . validate ( mapping , request );
if ( errors != null && ! errors . empty ()) {
saveErrors ( request , errors );
return mapping . findForward ( "telaInicialAbas" );
}
String ip = ( String ) request . getSession (). getAttribute ( "HOST_USUARIO" );
DTOIdentificacaoSegurancaSessao identificacaoSeguranca = new DTOIdentificacaoSegurancaSessao ();
identificacaoSeguranca . setIp ( ip );
User usuario = ( User ) request . getSession (). getAttribute ( "Usuario" );
carregarObjetosTelaConfirmacao ( form );
getGerenteEntorpecente (). incluirProcedimento ( form , usuario . getPerfilOperador (), identificacaoSeguranca );
} catch ( Exception e ) {
e . printStackTrace ();
generalError ( request , e . getMessage ());
return mapping . findForward ( "error" );
}
return mapping . findForward ( "success" );
}
Método de Validação no FORM ( VisaoProcedimento )
----------------------------------------------------------------
protected void doValidarVisaoOpt ( Map & lt ; String , String & gt ; mapaDeErros ) {
if ( UtilComum . isNull ( getDataInstauracaoProc ()) || getDataInstauracaoProc (). length () == 0 ) {
mapaDeErros . put ( "dataInstauracaoProc" , String . format ( ErrosEntorpecentes . CAMPO_OBRIGATORIO . getMensagem (), "\"Data Apreensão\"" ));
}
if ( UtilComum . isNull ( getNumeroProcedimento ()) || getNumeroProcedimento (). length () == 0 ) {
mapaDeErros . put ( "numeroProcedimento" , String . format ( ErrosEntorpecentes . CAMPO_OBRIGATORIO . getMensagem (), "\"Número Procedimento\"" ));
}
if ( getTipoProcedimento () != null
&& ( UtilComum . isNull ( getTipoProcedimento (). getSeqTipoProcedimento ()) || getTipoProcedimento ()
. getSeqTipoProcedimento () == 0 )) {
mapaDeErros . put ( "tipoProcedimento.seqTipoProcedimento" , String . format ( ErrosEntorpecentes . CAMPO_OBRIGATORIO . getMensagem (), "\"Tipo Procedimento\"" ));
}
if ( getMunicipio () != null && getMunicipio (). getUf () != null
&& ( UtilComum . isNull ( getMunicipio (). getUf (). getSigUf ()) || "" . equals ( getMunicipio (). getUf (). getSigUf ()))) {
mapaDeErros . put ( "municipio.uf.sigUf" , String . format ( ErrosEntorpecentes . CAMPO_OBRIGATORIO . getMensagem (), "\"UF Instauração\"" ));
}
if ( getMunicipio () != null
&& ( UtilComum . isNull ( getMunicipio (). getCodigoMunicipio ()) || getMunicipio (). getCodigoMunicipio () == 0 )) {
mapaDeErros . put ( "municipio.codigoMunicipio" , String . format ( ErrosEntorpecentes . CAMPO_OBRIGATORIO . getMensagem (), "\"Município\"" ));
}
if ( getOrgaoInstaurador () != null
&& getOrgaoInstaurador (). getInstituicaoPolicial () != null
&& ( UtilComum . isNull ( getOrgaoInstaurador (). getInstituicaoPolicial (). getSeqInstituicaoPolicial ()) || getOrgaoInstaurador ()
. getInstituicaoPolicial (). getSeqInstituicaoPolicial () == 0 )) {
mapaDeErros . put ( "orgaoInstaurador.instituicaoPolicial.seqInstituicaoPolicial" ,
String . format ( ErrosEntorpecentes . CAMPO_OBRIGATORIO . getMensagem (), "\"Instituição Policial\"" ));
}
if ( getOrgaoInstaurador () != null
&& ( UtilComum . isNull ( getOrgaoInstaurador (). getSeqOrgaoInstaurador ()) || getOrgaoInstaurador ()
. getSeqOrgaoInstaurador () == 0 )) {
mapaDeErros . put ( "orgaoInstaurador.seqOrgaoInstaurador" , String . format ( ErrosEntorpecentes . CAMPO_OBRIGATORIO . getMensagem (), "\"Órgão Instaurador\"" ));
}
if ( getResponsavelIniciativaApreensao () != null
&& ( UtilComum . isNull ( getResponsavelIniciativaApreensao (). getSeqOrgIniciativaApreensao ()) || getResponsavelIniciativaApreensao ()
. getSeqOrgIniciativaApreensao () == 0 )) {
mapaDeErros . put ( "responsavelIniciativaApreensao.seqOrgIniciativaApreensao" ,
String . format ( ErrosEntorpecentes . CAMPO_OBRIGATORIO . getMensagem (), "\"Iniciativa Apreensão\"" ));
}
if ( UtilComum . isNull ( getCartorio ()) || getCartorio (). length () == 0 ) {
mapaDeErros . put ( "cartorio" , String . format ( ErrosEntorpecentes . CAMPO_OBRIGATORIO . getMensagem (), "\"Cartório\"" ));
}
}
public ActionErrors validate ( ActionMapping mapping , HttpServletRequest request ) {
ActionErrors aes = super . validate ( mapping , request );
return aes ;
}