Struts 2 anotação pojo

0 respostas
I

Classe action

//declaração de pacotes 
public class ActionMap extends ActionSupport implements  ModelDriven<Cliente> {
  
    private Cliente cliente ;

    public String cadastrar()  {

		System.out.println("Passou aqui no cadastrar.");
		
		return Action.SUCCESS ;
		
    }

    @Override
	public Cliente getModel() {
		// TODO Auto-generated method stub
		return cliente;
	}
}

Classe Model

@Validation
public class Cliente {

	
	private String nome ;

	
	public Cliente(){}
	
	
	public final String getNome() {
		return nome;
	}

	@RequiredStringValidator(message = "You must enter a value for string." , trim=true)
	public final void setNome(String nome) {
		this.nome = nome;
	}
	
}

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    
    <include file="struts-default.xml" />

    <package name="default" extends="struts-default">
        
         <action name="Cadastro" method="cadastrar" class="pkg.action.ActionMap">
           <result name="success"> login.jsp </result>
           <result name="input"> cadastro.jsp </result>
        </action>
        
    </package>
</struts>

formulario

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s"  uri="/struts-tags"%>
<html>
<head>
	<link rel="shortcut icon" href="./imagem/Brasao.ico">
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<title>.::TCE - AM::.</title>
	<s:head/>
</head>
<body>
<br>
<br>
	<center>
		
			
			<s:form action="Cadastro" validate="true" theme="simple">
				Nome : <s:textfield name="nome" size="30" maxlength="30" />
					   <s:submit value="Login »" align="center" />	
			</s:form>
		
	</center>
	<br>
	<center>
				
					<s:fielderror>
            			<s:param value="%{'nome'}" />
        			</s:fielderror>
					
	</center>	
</body>
</html>

Gente esta funcionando minha action direitinho só que nao esta validando a pagina ?!?!?! Tem algo de errado na minha anotação

Criado 11 de fevereiro de 2009
Respostas 0
Participantes 1