Erro - a mensagem do Validator do Struts 2 não é exibida

0 respostas
elitefarias2329

Olá Galera, estou usando o Struts 2, e na hora de fazer a validação dos campos usando o Validator, me deparei com uma coisa ruim de resolver, a validação é realizada,
mas as mensagens definidas entre as tags no xml de validação.

Segue o projeto:

JSP:
<body>
		
		<div align="center" id="divTitulo">
			
			<p> Alteração - Centro de Custos</p>
			
		</div>
		
		
		<div class="posic_tabLista" align="center">
			<s:form action="alterarCentroCustos!actAlterarCentroCustos" id="form" 
					theme="simple" validate="true" >
				
					<s:hidden name="centroCustos.id"/>
					
					<table class="tabLista">
						<tr>
							<th>Dados - Centro de Custos</th>
						</tr>
						
						<tr>
							<td>
								<s:textfield label="Sigla" name="centroCustos.sigla"/>
							</td>
						</tr>
						
						<tr>
							<td>
								<s:textfield  label="Descrição" name="centroCustos.descricao"/>
							</td>
						</tr>
						
				
						
					</table>
							
					<table>
						
						<tr>
							<td>
								<a href="centroCustos!actListaCentroCustos">
									<img src="images/bt_cancelar.jpg" title="Cancelar Alteração" />
								</a>
							</td>
						</tr>
									
						<tr>
							<td>
								<a href="#" onclick="submitForm();">
									<img src="images/bt_confirmar.gif" title="Confirmar Alteração" />
								</a>
							</td>
						</tr>
					</table>
	                      </s:form>
			</div>
                  </body>

Action:

private List<CentroCustos> listaCentroCustos;
	private CentroCustosDAO dao = new CentroCustosDAO() ;
	private CentroCustos centroCustos = new CentroCustos();
	private String retorno = "success";
	 
		


	public String actAlterarCentroCustos()
	{
		CentroCustos cc = new CentroCustos();
		List<CentroCustos> lista = new ArrayList<CentroCustos>();
		
		try 
		{ 			 
			cc = centroCustos; 
			dao.alterarCentroCustos(cc);
			Integer idt = new Integer(cc.getId());
			String id = idt.toString();
			
			lista.add(dao.retornaCentroCustos(id));
			setListaCentroCustos(lista) ;
			
			
						
		} catch (Exception e) 
		{
			
			e.printStackTrace();
			retorno = "fail";

		}
		
		return retorno;
		
	}
	

	
	//Getter's e Setter's

Struts.xml:

<action name="alterarCentroCustos!*" method="{1}" class="br.com.controleContasWeb.actions.AlterarCentroCustosAction">
			
			<result name="input">/WEB-INF/jsp/centroCustos/alterarCentroCustos.jsp</result>
			<result name="success">/WEB-INF/jsp/centroCustos/centroCustos.jsp</result>
		
		</action>


AlterarCentroCustosAction-validation.xml
:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC
              "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
              "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
              
           <validators>
               
               
               	<field name="centroCustos.sigla">
           			<field-validator type="requiredstring">
						<message>Campo errado Teste</message>
           		</field-validator>
           	</field>
           	
           	           
               	<field name="centroCustos.descricao">
           			<field-validator type="requiredstring">
						<message>Campo errado Teste 2</message>
           		</field-validator>
           	</field>
           	
           	
  
           </validators>
Criado 22 de outubro de 2009
Respostas 0
Participantes 1