Dicas para concluir um projeto com Struts

23 respostas
fsa_net

Saudações Javanesas!

Eu preciso concluir o meu primeiro projeto para a Web. E gostaria de contar com o apoio da comunidade para que eu consiga ENTENDER e FAZER três coisas com o Jakarta-Struts:

:arrow: Processo de logon;p
:arrow: Capturar dados de um form e gravar no SGDB;
:arrow: Configurar o Controller do Struts para gerenciar o acesso as páginas, isto é, efetuar o mapeamento das minhas páginas.

O objetivo do projeto é um tracional catálogo de produtos, onde o usuário para acessar este catálogo deve estar registrado. Ele irá escolher os produtos receber um e-mail de confirmação e fim do projeto.

No momento o que tenho são todos os forms no padrão do Struts, acessando os objetos Javabeans, FormBeans e Actions, que defini para cada form.

Os problemas começam no logon que eu adaptei do strtus-example, aquela aplicação de exemplo do Struts. Quando digito a senha incorreta aparecem null null.
Se digito a senha correta aparece uma página em branco com o url: http://s1:8088/cotacaoonline/logon.do

Tenho quase certeza que deve ser algum problema no mapeamento. No final do LogonAction existe um return com Sucess, que deveria chamar uma página que defini, porém isto não acontece.

:?: Outro problema é como devo proceder para gravar os dados no SGDB. Crio um metodo no JavaBeans para isto?

Obrigado :!:

23 Respostas

fsamir

Olá,

o terceiro ponto (“Configurar o Controller do Struts para gerenciar o acesso as páginas, isto é, efetuar o mapeamento das minhas páginas.”)também me interessa muito. Seria óimo ver um exemplo.

Rafael_Steil

Pelamordedeus, alguem faca um tutorial de Struts URGENTE. Ta valendo R$ 200,00 em livros.

Rafael

urubatan

o struts gerenciar o acesso as páginas é só criar um action do tipo forward :-)

não precisa nem de classe para isto :-)

<action
forward="/caminho/para/servlet/ou/pagina.jsp"
path="/pageforward"
scope="session"
unknown="false"
validate="false" />

dentro do action-mappings

eu estou utilizando o tiles para gerenciar o layout das paginas, ai criei uma ActionClass generica e altero as configuracoes apenas nas actions :-)

olha só :-)

package br.com.usiinformatica.machinfo.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/** 
 * TilesProcessorAction.java created by EasyStruts - XsltGen.
 * http&#58;//easystruts.sf.net
 * created on 03-14-2003
 * 
 * XDoclet definition&#58;
 * @struts&#58;action validate=&quot;true&quot;
 * @struts&#58;action-forward name=&quot;indexDef&quot; path=&quot;indexDef&quot;
 */
public class TilesProcessorAction extends Action &#123;

	// --------------------------------------------------------- Instance Variables

	// --------------------------------------------------------- Methods

	/** 
	 * Method execute
	 * @param ActionMapping mapping
	 * @param ActionForm form
	 * @param HttpServletRequest request
	 * @param HttpServletResponse response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward execute&#40;
		ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response&#41;
		throws Exception &#123;

			return mapping.findForward&#40;&quot;success&quot;&#41;;
	&#125;

&#125;

e as actions ficam assim :-)

&lt;action
            path=&quot;/index&quot;
            scope=&quot;session&quot;
            type=&quot;br.com.usiinformatica.machinfo.action.TilesProcessorAction&quot;
            unknown=&quot;false&quot;
            validate=&quot;false&quot;&gt;
            &lt;forward
                name=&quot;success&quot;
                path=&quot;indexDef&quot;
                redirect=&quot;false&quot;
                contextRelative=&quot;false&quot; /&gt;
        &lt;/action&gt;
        &lt;action
            path=&quot;/licenses&quot;
            scope=&quot;session&quot;
            type=&quot;br.com.usiinformatica.machinfo.action.TilesProcessorAction&quot;
            unknown=&quot;false&quot;
            validate=&quot;false&quot;&gt;
            &lt;forward
                name=&quot;success&quot;
                path=&quot;licensesInputDef&quot;
                redirect=&quot;false&quot;
                contextRelative=&quot;false&quot; /&gt;
        &lt;/action&gt;
estes licensesInputDef e indexDef que ficam no lugar do caminho para as actions eu defini ni arquivo de configuraçã do tiles, que ficou mais ou menos assim :-)
&lt;definition name=&quot;defaultDef&quot; path=&quot;/pages/layout.jsp&quot;&gt;
		&lt;put name=&quot;header&quot; value=&quot;/pages/header.jsp&quot;/&gt;
		&lt;put name=&quot;footer&quot; value=&quot;/pages/footer.jsp&quot;/&gt;
		&lt;put name=&quot;body&quot; value=&quot;&quot;/&gt;
	&lt;/definition&gt;
	&lt;definition name=&quot;indexDef&quot; extends=&quot;defaultDef&quot;&gt;
		&lt;put name=&quot;body&quot; value=&quot;/pages/index.jsp&quot;/&gt;
	&lt;/definition&gt;
	&lt;definition name=&quot;licensesDef&quot; extends=&quot;defaultDef&quot;&gt;
		&lt;put name=&quot;body&quot; value=&quot;/pages/licenses.jsp&quot;/&gt;
	&lt;/definition&gt;

assim, alterando apenas os arquivos de configuração altero o conteúdo das paginas :-)

da para fazer a action forward ou entao utilizar algo parecido com o forward apontando para uma pagina para o struts controlar o acesso as JSP :-)

[/quote]

fsa_net

Urubatan,

E como você utiliza o Struts para os outros pontos que mencionei acima?

fsa_net

“Rafael Steil”:
Pelamordedeus, alguem faca um tutorial de Struts URGENTE. Ta valendo R$ 200,00 em livros.

Rafael

Tem um tutorial aqui na JSPBrasil
http://www.jspbrasil.com.br:8081/jspbrasil/artigos/struts.jsp

fsa_net

Quem já desenvolveu um site com o Struts, me diz como você:

Salvou os dados de um form em SGDB;

Nos Actions, reencaminhou o fluxo de página após salvar um form;

E realizou o logon.

Eu preciso muito mais entender como o processo funciona, do que ver código, já que nenhum código será aplicado em projeto sem que eu faça uma alteração.

Muito obrigado pela atenção. 8)

urubatan

capturar dados do form é o seguinte,
os dados do form, vem na objeto form para a ActionClass,
e acesso ao DB, eu configuro um datasource no arquivo de configuração do struts e acesso este datasource de dentro das ActionClass pelo metodo
getDataSource(request)

se tiver mais de um datasource na aplicação, basta especificar o nome também para o metodo get datasource :slight_smile:

para guardar os dados no DB, é só trabalhar com este datasource, getConnection() e por ai vai :slight_smile:

mas costumo criar uma classe DAO para esconder do resto da aplicação todo o codigo de tratamento e acesso a dados, e passo este datasource para a classe dao paraela utilizar os datasources do struts no acesso a dados :slight_smile:

tentei utilizar frameworks de O/R mapping, mas achei muito trabalho para quase nada, e pouca flexibilidade quanto ao modelo de dados também, ai parti para o DAO :slight_smile:

e a parte de logon, eu gosto de controlar isto sozinho, ai utilizo esta parte de acesso a DB para consultar o usuário e a senha se batem com o que o usuário digitou em um form :slight_smile:

vou postar outra resposta com um exemplo do que to falando, ta em outra maquina :slight_smile:

urubatan
configuracao datasource no struts:
&lt;data-source key=&quot;org.apache.struts.action.DATA_SOURCE&quot; type=&quot;org.apache.struts.util.GenericDataSource&quot;&gt;
            &lt;set-property property=&quot;password&quot; value=&quot;********&quot; /&gt;
            &lt;set-property property=&quot;minCount&quot; value=&quot;&quot; /&gt;
            &lt;set-property property=&quot;maxCount&quot; value=&quot;&quot; /&gt;
            &lt;set-property property=&quot;user&quot; value=&quot;*********&quot; /&gt;
            &lt;set-property property=&quot;driverClass&quot; value=&quot;org.firebirdsql.jdbc.FBDriver&quot; /&gt;
            &lt;set-property property=&quot;description&quot; value=&quot;MachInfo DataSource&quot; /&gt;
            &lt;set-property property=&quot;url&quot; value=&quot;jdbc&#58;firebirdsql&#58;localhost/3050&#58;c&#58;\firebird\usimachinfo.gdb&quot; /&gt;
            &lt;set-property property=&quot;readOnly&quot; value=&quot;false&quot; /&gt;
            &lt;set-property property=&quot;autoCommit&quot; value=&quot;true&quot; /&gt;
            &lt;set-property property=&quot;loginTimeout&quot; value=&quot;&quot; /&gt;
        &lt;/data-source&gt;

acesso ao datasource, e delegar responsabilidade para classe dao :-)

package br.com.usiinformatica.machinfo.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import br.com.usiinformatica.machinfo.dao.MaquinaDAOImpl;
import br.com.usiinformatica.machinfo.dao.MaquinaXMLImpl;
import br.com.usiinformatica.machinfo.form.ManualUploadMachineXmlForm;
import br.com.usiinformatica.machinfo.webapp.MaquinaDAO;
import br.com.usiinformatica.machinfo.webapp.MaquinaXML;

/** 
 * ManualUploadMachineXmlAction.java created by EasyStruts - XsltGen.
 * http&#58;//easystruts.sf.net
 * created on 03-14-2003
 * 
 * XDoclet definition&#58;
 * @struts&#58;action path=&quot;/manualUploadMachineXml&quot; name=&quot;manualUploadMachineXmlForm&quot; input=&quot;/form/manualUploadMachineXml.jsp&quot; validate=&quot;true&quot;
 * @struts&#58;action-forward name=&quot;/pages/uploadErr.jsp&quot; path=&quot;/pages/uploadErr.jsp&quot; redirect=&quot;true&quot; contextRelative=&quot;true&quot;
 * @struts&#58;action-forward name=&quot;/pages/UploadOK.jsp&quot; path=&quot;/pages/UploadOK.jsp&quot; redirect=&quot;true&quot; contextRelative=&quot;true&quot;
 */
public class ManualUploadMachineXmlAction extends Action &#123;

	// --------------------------------------------------------- Instance Variables

	// --------------------------------------------------------- Methods

	/** 
	 * Method execute
	 * @param ActionMapping mapping
	 * @param ActionForm form
	 * @param HttpServletRequest request
	 * @param HttpServletResponse response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward execute&#40;
		ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response&#41;
		throws Exception &#123;
		ManualUploadMachineXmlForm manualUploadMachineXmlForm =
			&#40;ManualUploadMachineXmlForm&#41; form;
		MaquinaDAO maq = new MaquinaDAOImpl&#40;&#41;;
		MaquinaXML xml =
			new MaquinaXMLImpl&#40;manualUploadMachineXmlForm.getMachineXML&#40;&#41;&#41;;
		maq.setDataSource&#40;this.getDataSource&#40;request&#41;&#41;;
		maq.store&#40;xml.getMachine&#40;&#41;&#41;;
		return mapping.findForward&#40;&quot;uploadOk&quot;&#41;;
	&#125;

&#125;

FormClass :-) altamente complexo :-)

package br.com.usiinformatica.machinfo.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

/** 
 * ManualUploadMachineXmlForm.java created by EasyStruts - XsltGen.
 * http&#58;//easystruts.sf.net
 * created on 03-14-2003
 * 
 * XDoclet definition&#58;
 * @struts&#58;form name=&quot;manualUploadMachineXmlForm&quot;
 */
public class ManualUploadMachineXmlForm extends ActionForm &#123;

	// --------------------------------------------------------- Instance Variables

	/** uploaderPassword property */
	private String uploaderPassword;

	/** machineXML property */
	private String machineXML;

	/** uploaderName property */
	private String uploaderName;

	// --------------------------------------------------------- Methods

	/** 
	 * Method validate
	 * @param ActionMapping mapping
	 * @param HttpServletRequest request
	 * @return ActionErrors
	 */
	public ActionErrors validate&#40;
		ActionMapping mapping,
		HttpServletRequest request&#41; &#123;

		throw new UnsupportedOperationException&#40;&quot;Generated method 'validate&#40;...&#41;' not implemented.&quot;&#41;;
	&#125;

	/** 
	 * Method reset
	 * @param ActionMapping mapping
	 * @param HttpServletRequest request
	 */
	public void reset&#40;ActionMapping mapping, HttpServletRequest request&#41; &#123;
		uploaderPassword = &quot;&quot;;
		machineXML = &quot;&quot;;
		uploaderName = &quot;&quot;;

	&#125;

	/** 
	 * Returns the uploaderPassword.
	 * @return String
	 */
	public String getUploaderPassword&#40;&#41; &#123;
		return uploaderPassword;
	&#125;

	/** 
	 * Set the uploaderPassword.
	 * @param uploaderPassword The uploaderPassword to set
	 */
	public void setUploaderPassword&#40;String uploaderPassword&#41; &#123;
		this.uploaderPassword = uploaderPassword;
	&#125;

	/** 
	 * Returns the machineXML.
	 * @return String
	 */
	public String getMachineXML&#40;&#41; &#123;
		return machineXML;
	&#125;

	/** 
	 * Set the machineXML.
	 * @param machineXML The machineXML to set
	 */
	public void setMachineXML&#40;String machineXML&#41; &#123;
		this.machineXML = machineXML;
	&#125;

	/** 
	 * Returns the uploaderName.
	 * @return String
	 */
	public String getUploaderName&#40;&#41; &#123;
		return uploaderName;
	&#125;

	/** 
	 * Set the uploaderName.
	 * @param uploaderName The uploaderName to set
	 */
	public void setUploaderName&#40;String uploaderName&#41; &#123;
		this.uploaderName = uploaderName;
	&#125;

&#125;

Todas as propriedades do ActionForm são setadas pelo proprio struts, não tem que se preocupar com isto :-)

R

Eu particulamente prefiro não usar o pool do Struts, usamos um pool implementado aqui na empresa, nossas Actions tem acesso a fachada do sistema e todo acesso aos dados fica na camada de repositório de dados.

Essa camada é independente e pode tanto usar nosso pool, ou trabalhar com EJB, JDO etc.

urubatan

é uma abordagem legal também :slight_smile:
eu delego isto para a classe DAO, que pode acessar direto por JDBC, ou utilizar um EJB :slight_smile:
mas por enquanto continuo só com o JDBC nos projetos que estou usando o struts :slight_smile:

fsa_net

Urubatan,

[i]Eu estou quase compreendendo todo o processo de trabalho com o Struts… Vamos lá

:arrow: Abaixo um trecho do meu struts-config, neste ponto estou configurando o Controller para a minha aplicação. [/i]

&lt;!-- ========== Form Bean Definitions =================================== --&gt;

  &lt;form-beans&gt;
    &lt;!-- Usuario form bean --&gt;
    &lt;form-bean name="usuarioForm" type="src.struts.UsuarioForm"/&gt;

  &lt;/form-beans&gt;

  &lt;!-- ========== Action Mapping Definitions ============================== --&gt;

  &lt;action-mappings&gt;

    &lt;!-- /usuario - Action para o form do frmUsuario.jsp.--&gt;
    &lt;action type="src.struts.UsuarioAction" 
            name="usuarioForm" 
            path="/usuario" 
            scope="request"
            input="/frmUsuario.jsp"
            validate="true"&gt;
            &lt;forward name="success" path="/index.jsp"/&gt;
    &lt;/action&gt;

  &lt;/action-mappings&gt;

[i]
Na seção “Form Bean Definitions”, descrevo o nome do form e a classe que irá capturar e retornar todos os campos do meu form.
Em “Action Mapping Definitions”, irei associar o FormBean a uma sub-classe Action.

Onde devem estar os metodos de persistência e de negócio :?: No FormBean ou no objeto JavaBean :?:

Para cada form eu criei um JavaBean e um FormBean, estou na dúvida se preciso dos dois :?:
[/i]

:arrow: Código para o UsuarioAction

public ActionForward perform&#40;ActionMapping mapping,
				 ActionForm form,
				 HttpServletRequest request,
				 HttpServletResponse response&#41;
	throws IOException, ServletException &#123;

	// Extract attributes we will need
	Locale locale = getLocale&#40;request&#41;;
	MessageResources messages = getResources&#40;&#41;;
	Usuario usuario = null;

	// Validate the request parameters specified by the usuario
	ActionErrors errors = new ActionErrors&#40;&#41;;
	String nome = &#40;&#40;UsuarioForm&#41; form&#41;.getNome&#40;&#41;;
	String dddres = &#40;&#40;UsuarioForm&#41; form&#41;.getDddres&#40;&#41;;
	String telefoneres = &#40;&#40;UsuarioForm&#41; form&#41;.getTelefoneres&#40;&#41;;
	String endereco = &#40;&#40;UsuarioForm&#41; form&#41;.getEndereco&#40;&#41;;
	String bairro = &#40;&#40;UsuarioForm&#41; form&#41;.getBairro&#40;&#41;;
	String cidade = &#40;&#40;UsuarioForm&#41; form&#41;.getCidade&#40;&#41;;
	String estado = &#40;&#40;UsuarioForm&#41; form&#41;.getEstado&#40;&#41;;
	String cep = &#40;&#40;UsuarioForm&#41; form&#41;.getCep&#40;&#41;;
	String logonusuario = &#40;&#40;UsuarioForm&#41; form&#41;.getUsuario&#40;&#41;;
	String email = &#40;&#40;UsuarioForm&#41; form&#41;.getEmail&#40;&#41;;
	String senha = &#40;&#40;UsuarioForm&#41; form&#41;.getSenha&#40;&#41;;
	String senha2 = &#40;&#40;UsuarioForm&#41; form&#41;.getSenha2&#40;&#41;;
	String empresa = &#40;&#40;UsuarioForm&#41; form&#41;.getEmpresa&#40;&#41;;
	String depto = &#40;&#40;UsuarioForm&#41; form&#41;.getDepto&#40;&#41;;
	String cargo = &#40;&#40;UsuarioForm&#41; form&#41;.getCargo&#40;&#41;;
	String dddcom = &#40;&#40;UsuarioForm&#41; form&#41;.getDddcom&#40;&#41;;
	String telefonecom = &#40;&#40;UsuarioForm&#41; form&#41;.getTelefonecom&#40;&#41;;
        
        // Variavel local para acesso ao SGDB
        java.sql.Connection myConnection = null;
        
        /*
         * Utiliza o DataSource para obter uma nova conexão ao SGDB
         */
        try &#123;
            javax.sql.DataSource dataSource =
            servlet.findDataSource&#40;null&#41;;
            
            myConnection = dataSource.getConnection&#40;&#41;;
            
            //do what you wish with myConnection
        &#125; catch &#40;SQLException sqle&#41; &#123;
            getServlet&#40;&#41;.log&#40;"Connection.process", sqle&#41;;
        &#125; finally &#123;
            
            //enclose this in a finally block to make
            //sure the connection is closed
            try &#123;
                myConnection.close&#40;&#41;;
            &#125; catch &#40;SQLException e&#41; &#123;
                getServlet&#40;&#41;.log&#40;"Connection.close", e&#41;;
            &#125;
        &#125;


	// Report any errors we have discovered back to the original form
	if &#40;!errors.empty&#40;&#41;&#41; &#123;
	    saveErrors&#40;request, errors&#41;;
	    return &#40;new ActionForward&#40;mapping.getInput&#40;&#41;&#41;&#41;;
	&#125;

	// Forward control to the specified success URI
	return &#40;mapping.findForward&#40;"success"&#41;&#41;;

    &#125;

[i]Quando acesso o form e o envio. Fica na mesma página e surgem dois null’s.
A url fica assim: http://s1:8088/cotacaoonline/usuario.do

O quê estou fazendo de errado?[/i]

urubatan

O arquivo de configuração do struts parece estar perfeito :slight_smile:

eu costumo deixar o formbean apenas como um esqueleto para acessar os parametros da pagina e fazer alguma validação de parametros :slight_smile:

você pode colocar metodos de negocio/percistencia dentro das actions, mas prefiro criar classes especializadas nisto, ai posso acessar a mesma coisa de mais de uma action :slight_smile:

mais ou menos como o exemplo que postei acima, os metodos de persistencia e de negocio eram acessados pela interface MaquinaDAO, assim eu podia acessa-los de mais de um lugar no sistema :slight_smile:

agora quanto ao erro, pode ser alguma coisa na pagina, poste o codigo da JSP de input do Form aqui para eu dar uma olhada :slight_smile:

fsa_net

Olá Urubatan.

Outra dúvida... Eu criei um JavaBean para cada form com metodos setXXX() / getXXX() / toString(). Agora com seus comentários imagino que toda a lógina de negócios posso colocar neste JavaBean e retirar os metódos setXXX() / getXXX().

:arrow: JavaBean Usuario
package src.struts;

import java.io.Serializable;
import java.util.Enumeration;
import java.util.Hashtable;

/**
 * Implementacao de &lt;strong&gt;Action&lt;/strong&gt; que valida um registro do 
 * cadastro de usuario.
 *
 * @author Fabio Santos Almeida
 * @version $Revision&#58; 1.2 $ $Date&#58; 2001/04/14 12&#58;53&#58;08 $
 */

public final class Usuario implements Serializable &#123;
    
    
    // --------------------------------------------------- Instance Variables
    
    
    
    /**
     * The nome.
     */
    private String nome = null;  
    
    
    /**
     * The dddres.
     */
    private String dddres  	= null;
    
    /**
     * The telefoneres.
     */
    private String telefoneres	= null;
    
    
    
    /**
     * The endereco.
     */
    private String endereco        = null;
    
    
    /**
     * The bairro.
     */
    private String bairro          = null;
    
    
    /**
     * The cidade.
     */
    private String cidade		= null;
    
    
    /**
     * The estado.
     */
    private String estado		= null;
    
    
    /**
     * The cep.
     */
    private String cep             = null;
    
    
    
    /**
     * The id.
     */
    private String usuario              = null;
    
    
    /**
     * The email.
     */
    private String email		= null;
    
    
    /**
     * The senha.
     */
    private String senha	= null;
    
    
    /**
     * The senha2.
     */
    private String senha2	= null;    
    
    
    /**
     * The empresa.
     */
    private String empresa		= null;
    
    
    /**
     * The depto.
     */
    private String depto		= null;
    
    
    /**
     * The cargo.
     */
    private String cargo		= null;
    
    
    /**
     * The dddcom.
     */
    private String dddcom  	= null;
    
    
    /**
     * The telefonecom.
     */
    private String telefonecom	= null;
    
    
    // ----------------------------------------------------------- Properties
    /**
     * Return the nome.
     */
    public String getNome&#40;&#41; &#123;
        
        return &#40;this.nome&#41;;
        
    &#125;
    
    
    /**
     * Set the nome.
     *
     * @param nome The new nome
     */
    public void setNome&#40;String nome&#41; &#123;
        
        this.nome = nome;
        
    &#125;
    
    
    /**
     * Return the dddres.
     */
    public String getDddres&#40;&#41; &#123;
        
        return &#40;this.dddres&#41;;
        
    &#125;
    
    
    /**
     * Set the dddres.
     *
     * @param dddres The new dddres
     */
    public void setDddres&#40;String dddres&#41; &#123;
        
        this.dddres = dddres;
        
    &#125;
    
    
    
    
    
    /**
     * Return the telefoneres.
     */
    public String getTelefoneres&#40;&#41; &#123;
        
        return &#40;this.telefoneres&#41;;
        
    &#125;
    
    
    /**
     * Set the telefoneres.
     *
     * @param telefoneres The new telefoneres
     */
    public void setTelefoneres&#40;String telefoneres&#41; &#123;
        
        this.telefoneres = telefoneres;
        
    &#125;
    
    
    
    
    
    /**
     * Return the endereco.
     */
    public String getEndereco&#40;&#41; &#123;
        
        return &#40;this.endereco&#41;;
        
    &#125;
    
    
    /**
     * Set the endereco.
     *
     * @param endereco The new endereco
     */
    public void setEndereco&#40;String endereco&#41; &#123;
        
        this.endereco = endereco;
        
    &#125;
    
    
    
    
    /**
     * Return the bairro.
     */
    public String getBairro&#40;&#41; &#123;
        
        return &#40;this.bairro&#41;;
        
    &#125;
    
    
    /**
     * Set the bairro.
     *
     * @param bairro The new bairro
     */
    public void setBairro&#40;String bairro&#41; &#123;
        
        this.bairro = bairro;
        
    &#125;
    
    
    
    
    
    /**
     * Return the cidade.
     */
    public String getCidade&#40;&#41; &#123;
        
        return &#40;this.cidade&#41;;
        
    &#125;
    
    
    /**
     * Set the cidade.
     *
     * @param cidade The new cidade
     */
    public void setCidade&#40;String cidade&#41; &#123;
        
        this.cidade = cidade;
        
    &#125;
    
    
    
    
    
    /**
     * Return the estado.
     */
    public String getEstado&#40;&#41; &#123;
        
        return &#40;this.estado&#41;;
        
    &#125;
    
    
    /**
     * Set the estado.
     *
     * @param estado The new estado
     */
    public void setEstado&#40;String estado&#41; &#123;
        
        this.estado = estado;
        
    &#125;
    
    
    
    
    
    /**
     * Return the cep.
     */
    public String getCep&#40;&#41; &#123;
        
        return &#40;this.cep&#41;;
        
    &#125;
    
    
    /**
     * Set the cep.
     *
     * @param cep The new cep
     */
    public void setCep&#40;String cep&#41; &#123;
        
        this.cep = cep;
        
    &#125;
    
    
    
    
    
    /**
     * Return the usuario.
     */
    public String getUsuario&#40;&#41; &#123;
        
        return &#40;this.usuario&#41;;
        
    &#125;
    
    
    /**
     * Set the usuario.
     *
     * @param usuario The new usuario
     */
    public void setUsuario&#40;String usuario&#41; &#123;
        
        this.usuario = usuario;
        
    &#125;
    
    
    
    
    
    /**
     * Return the email.
     */
    public String getEmail&#40;&#41; &#123;
        
        return &#40;this.email&#41;;
        
    &#125;
    
    
    /**
     * Set the email.
     *
     * @param email The new email
     */
    public void setEmail&#40;String email&#41; &#123;
        
        this.email = email;
        
    &#125;
    
    
    
    
    
    /**
     * Return the senha.
     */
    public String getSenha&#40;&#41; &#123;
        
        return &#40;this.senha&#41;;
        
    &#125;
    
    
    /**
     * Set the senha.
     *
     * @param senha The new senha
     */
    public void setSenha&#40;String senha&#41; &#123;
        
        this.senha = senha;
        
    &#125;
    
    
    
    
    
    /**
     * Return the senha2.
     */
    public String getSenha2&#40;&#41; &#123;
        
        return &#40;this.senha2&#41;;
        
    &#125;
    
    
    /**
     * Set the senha2.
     *
     * @param senha The new senha2
     */
    public void setSenha2&#40;String senha2&#41; &#123;
        
        this.senha2 = senha2;
        
    &#125;
    
    
    
    
    
    /**
     * Return the empresa.
     */
    public String getEmpresa&#40;&#41; &#123;
        
        return &#40;this.empresa&#41;;
        
    &#125;
    
    
    /**
     * Set the empresa.
     *
     * @param empresa The new empresa
     */
    public void setEmpresa&#40;String empresa&#41; &#123;
        
        this.empresa = empresa;
        
    &#125;
    
    
    
    
    
    /**
     * Return the depto.
     */
    public String getDepto&#40;&#41; &#123;
        
        return &#40;this.depto&#41;;
        
    &#125;
    
    
    /**
     * Set the depto.
     *
     * @param depto The new depto
     */
    public void setDepto&#40;String depto&#41; &#123;
        
        this.depto = depto;
        
    &#125;
    
    
    
    
    
    /**
     * Return the cargo.
     */
    public String getCargo&#40;&#41; &#123;
        
        return &#40;this.cargo&#41;;
        
    &#125;
    
    
    /**
     * Set the cargo.
     *
     * @param cargo The new cargo
     */
    public void setCargo&#40;String cargo&#41; &#123;
        
        this.cargo = cargo;
        
    &#125;
    
    
    
    
    
    /**
     * Return the dddcom.
     */
    public String getDddcom&#40;&#41; &#123;
        
        return &#40;this.dddcom&#41;;
        
    &#125;
    
    
    /**
     * Set the dddcom.
     *
     * @param dddcom The new dddcom
     */
    public void setDddcom&#40;String dddcom&#41; &#123;
        
        this.dddcom = dddcom;
        
    &#125;
    
    
    
    
    
    /**
     * Return the telefonecom.
     */
    public String getTelefonecom&#40;&#41; &#123;
        
        return &#40;this.telefonecom&#41;;
        
    &#125;
    
    
    /**
     * Set the telefonecom.
     *
     * @param telefonecom The new telefonecom
     */
    public void setTelefonecom&#40;String telefonecom&#41; &#123;
        
        this.telefonecom = telefonecom;
        
    &#125;
    
    
    
    
    // --------------------------------------------------------- Public Methods
    
    public String toString&#40;&#41; &#123;
        StringBuffer sb = new StringBuffer&#40;&quot;&lt;usuario&gt;
	&lt;nome&gt;&quot;&#41;;
        sb.append&#40;nome&#41;;
        sb.append&#40;&quot;&lt;/nome&gt;
&quot;&#41;;
        
        sb.append&#40;&quot;	&lt;ddd&gt;&quot;&#41;;
        sb.append&#40;dddres&#41;;
        sb.append&#40;&quot;&lt;/ddd&gt;
&quot;&#41;;
        
        sb.append&#40;&quot;	&lt;telefoneres&gt;&quot;&#41;;
        sb.append&#40;telefoneres&#41;;
        sb.append&#40;&quot;&lt;/telefoneres&gt;
&quot;&#41;;
        
        sb.append&#40;&quot;	&lt;endereco&gt;&quot;&#41;;
        sb.append&#40;endereco&#41;;
        sb.append&#40;&quot;&lt;/endereco&gt;
&quot;&#41;;
        
        sb.append&#40;&quot;	&lt;bairro&gt;&quot;&#41;;
        sb.append&#40;bairro&#41;;
        sb.append&#40;&quot;&lt;/bairro&gt;
&quot;&#41;;
        
        sb.append&#40;&quot;	&lt;cidade&gt;&quot;&#41;;
        sb.append&#40;cidade&#41;;
        sb.append&#40;&quot;&lt;/cidade&gt;
&quot;&#41;;
        
        sb.append&#40;&quot;	&lt;estado&gt;&quot;&#41;;
        sb.append&#40;estado&#41;;
        sb.append&#40;&quot;&lt;/estado&gt;
&quot;&#41;;
        
        sb.append&#40;&quot;	&lt;cep&gt;&quot;&#41;;
        sb.append&#40;cep&#41;;
        sb.append&#40;&quot;&lt;/cep&gt;
&quot;&#41;;
        
        sb.append&#40;&quot;	&lt;usuario&gt;&quot;&#41;;
        sb.append&#40;usuario&#41;;
        sb.append&#40;&quot;&lt;/usuario&gt;
&quot;&#41;;
        
        sb.append&#40;&quot;	&lt;email&gt;&quot;&#41;;
        sb.append&#40;email&#41;;
        sb.append&#40;&quot;&lt;/email&gt;
&quot;&#41;;
        
        sb.append&#40;&quot;	&lt;senha&gt;&quot;&#41;;
        sb.append&#40;senha&#41;;
        sb.append&#40;&quot;&lt;/senha&gt;
&quot;&#41;;
        
        sb.append&#40;&quot;	&lt;senha2&gt;&quot;&#41;;
        sb.append&#40;senha2&#41;;
        sb.append&#40;&quot;&lt;/senha2&gt;
&quot;&#41;;
        
        if &#40;empresa != null&#41; &#123;
            sb.append&#40;&quot;	&lt;empresa&gt;&quot;&#41;;
            sb.append&#40;empresa&#41;;
            sb.append&#40;&quot;&lt;/empresa&gt;
&quot;&#41;;
        &#125;
        
        if &#40;depto != null&#41; &#123;
            sb.append&#40;&quot;	&lt;depto&gt;&quot;&#41;;
            sb.append&#40;depto&#41;;
            sb.append&#40;&quot;&lt;/depto&gt;
&quot;&#41;;
        &#125;
        
        if &#40;cargo != null&#41; &#123;
            sb.append&#40;&quot;	&lt;cargo&gt;&quot;&#41;;
            sb.append&#40;cargo&#41;;
            sb.append&#40;&quot;&lt;/cargo&gt;
&quot;&#41;;
        &#125;
        
        if &#40;dddcom != null&#41; &#123;
            sb.append&#40;&quot;	&lt;dddcom&gt;&quot;&#41;;
            sb.append&#40;dddcom&#41;;
            sb.append&#40;&quot;&lt;/dddcom&gt;
&quot;&#41;;
        &#125;
        
        if &#40;telefonecom != null&#41; &#123;
            sb.append&#40;&quot;	&lt;telefonecom&gt;&quot;&#41;;
            sb.append&#40;telefonecom&#41;;
            sb.append&#40;&quot;&lt;/telefonecom&gt;
&quot;&#41;;
        &#125;
        sb.append&#40;&quot;&lt;/usuario&gt;&quot;&#41;;
        
        return &#40;sb.toString&#40;&#41;&#41;;
    &#125;
&#125;
:arrow: FormBean = FormUsuario
package src.struts;


import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;


/**
 * Form bean for the user profile page.  This form has the following fields,
 * with default values in square brackets&#58;
 * &lt;ul&gt;
 * &lt;li&gt;&lt;b&gt;nome        &lt;/b&gt;&lt;/li&gt; - Entered  nome        value
 * &lt;li&gt;&lt;b&gt;dddres      &lt;/b&gt;&lt;/li&gt; - Entered  dddres      value
 * &lt;li&gt;&lt;b&gt;telefoneres &lt;/b&gt;&lt;/li&gt; - Entered  telefoneres value
 * &lt;li&gt;&lt;b&gt;endereco    &lt;/b&gt;&lt;/li&gt; - Entered  endereco    value
 * &lt;li&gt;&lt;b&gt;bairro      &lt;/b&gt;&lt;/li&gt; - Entered  bairro      value
 * &lt;li&gt;&lt;b&gt;cidade      &lt;/b&gt;&lt;/li&gt; - Entered  cidade      value
 * &lt;li&gt;&lt;b&gt;estado      &lt;/b&gt;&lt;/li&gt; - Entered  estado      value
 * &lt;li&gt;&lt;b&gt;cep         &lt;/b&gt;&lt;/li&gt; - Entered  cep         value
 * &lt;li&gt;&lt;b&gt;usuario     &lt;/b&gt;&lt;/li&gt; - Entered  usuario     value
 * &lt;li&gt;&lt;b&gt;email       &lt;/b&gt;&lt;/li&gt; - Entered  email       value
 * &lt;li&gt;&lt;b&gt;senha       &lt;/b&gt;&lt;/li&gt; - Entered  senha       value
 * &lt;li&gt;&lt;b&gt;senha2      &lt;/b&gt;&lt;/li&gt; - Entered  senha2      value
 * &lt;li&gt;&lt;b&gt;empresa     &lt;/b&gt;&lt;/li&gt; - Entered  empresa     value
 * &lt;li&gt;&lt;b&gt;depto       &lt;/b&gt;&lt;/li&gt; - Entered  depto       value
 * &lt;li&gt;&lt;b&gt;cargo       &lt;/b&gt;&lt;/li&gt; - Entered  cargo       value
 * &lt;li&gt;&lt;b&gt;dddcom      &lt;/b&gt;&lt;/li&gt; - Entered  dddcom      value
 * &lt;li&gt;&lt;b&gt;telefonecom &lt;/b&gt;&lt;/li&gt; - Entered  telefonecom value* &lt;/ul&gt;
 *
 * @author Fabio Santos Almeida
 * @version $Revision&#58; 1.2 $ $Date&#58; 2001/04/14 12&#58;53&#58;08 $
 */

public final class UsuarioForm extends ActionForm &#123;
    
    
    // --------------------------------------------------- Instance Variables
    
    
    
    /**
     * The nome.
     */
    private String nome = null;
    
    
    
    
    /**
     * The dddres.
     */
    private String dddres  	= null;
    
    /**
     * The telefoneres.
     */
    private String telefoneres	= null;
    
    
    
    /**
     * The endereco.
     */
    private String endereco        = null;
    
    
    /**
     * The bairro.
     */
    private String bairro          = null;
    
    
    /**
     * The cidade.
     */
    private String cidade		= null;
    
    
    /**
     * The estado.
     */
    private String estado		= null;
    
    
    /**
     * The cep.
     */
    private String cep             = null;
    
    
    
    /**
     * The id.
     */
    private String usuario              = null;
    
    
    /**
     * The email.
     */
    private String email		= null;
    
    
    /**
     * The senha.
     */
    private String senha	= null;
    
    
    /**
     * The senha2.
     */
    private String senha2	= null;    
    
    
    /**
     * The empresa.
     */
    private String empresa		= null;
    
    
    /**
     * The depto.
     */
    private String depto		= null;
    
    
    /**
     * The cargo.
     */
    private String cargo		= null;
    
    
    /**
     * The dddcom.
     */
    private String dddcom  	= null;
    
    
    /**
     * The telefonecom.
     */
    private String telefonecom	= null;
    
    
    // ----------------------------------------------------------- Properties
    /**
     * Return the nome.
     */
    public String getNome&#40;&#41; &#123;
        
        return &#40;this.nome&#41;;
        
    &#125;
    
    
    /**
     * Set the nome.
     *
     * @param nome The new nome
     */
    public void setNome&#40;String nome&#41; &#123;
        
        this.nome = nome;
        
    &#125;
    
    
    /**
     * Return the dddres.
     */
    public String getDddres&#40;&#41; &#123;
        
        return &#40;this.dddres&#41;;
        
    &#125;
    
    
    /**
     * Set the dddres.
     *
     * @param dddres The new dddres
     */
    public void setDddres&#40;String dddres&#41; &#123;
        
        this.dddres = dddres;
        
    &#125;
    
    
    
    
    
    /**
     * Return the telefoneres.
     */
    public String getTelefoneres&#40;&#41; &#123;
        
        return &#40;this.telefoneres&#41;;
        
    &#125;
    
    
    /**
     * Set the telefoneres.
     *
     * @param telefoneres The new telefoneres
     */
    public void setTelefoneres&#40;String telefoneres&#41; &#123;
        
        this.telefoneres = telefoneres;
        
    &#125;
    
    
    
    
    
    /**
     * Return the endereco.
     */
    public String getEndereco&#40;&#41; &#123;
        
        return &#40;this.endereco&#41;;
        
    &#125;
    
    
    /**
     * Set the endereco.
     *
     * @param endereco The new endereco
     */
    public void setEndereco&#40;String endereco&#41; &#123;
        
        this.endereco = endereco;
        
    &#125;
    
    
    
    
    /**
     * Return the bairro.
     */
    public String getBairro&#40;&#41; &#123;
        
        return &#40;this.bairro&#41;;
        
    &#125;
    
    
    /**
     * Set the bairro.
     *
     * @param bairro The new bairro
     */
    public void setBairro&#40;String bairro&#41; &#123;
        
        this.bairro = bairro;
        
    &#125;
    
    
    
    
    
    /**
     * Return the cidade.
     */
    public String getCidade&#40;&#41; &#123;
        
        return &#40;this.cidade&#41;;
        
    &#125;
    
    
    /**
     * Set the cidade.
     *
     * @param cidade The new cidade
     */
    public void setCidade&#40;String cidade&#41; &#123;
        
        this.cidade = cidade;
        
    &#125;
    
    
    
    
    
    /**
     * Return the estado.
     */
    public String getEstado&#40;&#41; &#123;
        
        return &#40;this.estado&#41;;
        
    &#125;
    
    
    /**
     * Set the estado.
     *
     * @param estado The new estado
     */
    public void setEstado&#40;String estado&#41; &#123;
        
        this.estado = estado;
        
    &#125;
    
    
    
    
    
    /**
     * Return the cep.
     */
    public String getCep&#40;&#41; &#123;
        
        return &#40;this.cep&#41;;
        
    &#125;
    
    
    /**
     * Set the cep.
     *
     * @param cep The new cep
     */
    public void setCep&#40;String cep&#41; &#123;
        
        this.cep = cep;
        
    &#125;
    
    
    
    
    
    /**
     * Return the usuario.
     */
    public String getUsuario&#40;&#41; &#123;
        
        return &#40;this.usuario&#41;;
        
    &#125;
    
    
    /**
     * Set the usuario.
     *
     * @param usuario The new usuario
     */
    public void setUsuario&#40;String usuario&#41; &#123;
        
        this.usuario = usuario;
        
    &#125;
    
    
    
    
    
    /**
     * Return the email.
     */
    public String getEmail&#40;&#41; &#123;
        
        return &#40;this.email&#41;;
        
    &#125;
    
    
    /**
     * Set the email.
     *
     * @param email The new email
     */
    public void setEmail&#40;String email&#41; &#123;
        
        this.email = email;
        
    &#125;
    
    
    
    
    
    /**
     * Return the senha.
     */
    public String getSenha&#40;&#41; &#123;
        
        return &#40;this.senha&#41;;
        
    &#125;
    
    
    /**
     * Set the senha.
     *
     * @param senha The new senha
     */
    public void setSenha&#40;String senha&#41; &#123;
        
        this.senha = senha;
        
    &#125;
    
    
    
    
    
    /**
     * Return the senha2.
     */
    public String getSenha2&#40;&#41; &#123;
        
        return &#40;this.senha2&#41;;
        
    &#125;
    
    
    /**
     * Set the senha2.
     *
     * @param senha The new senha2
     */
    public void setSenha2&#40;String senha2&#41; &#123;
        
        this.senha2 = senha2;
        
    &#125;
    
    
    
    
    
    /**
     * Return the empresa.
     */
    public String getEmpresa&#40;&#41; &#123;
        
        return &#40;this.empresa&#41;;
        
    &#125;
    
    
    /**
     * Set the empresa.
     *
     * @param empresa The new empresa
     */
    public void setEmpresa&#40;String empresa&#41; &#123;
        
        this.empresa = empresa;
        
    &#125;
    
    
    
    
    
    /**
     * Return the depto.
     */
    public String getDepto&#40;&#41; &#123;
        
        return &#40;this.depto&#41;;
        
    &#125;
    
    
    /**
     * Set the depto.
     *
     * @param depto The new depto
     */
    public void setDepto&#40;String depto&#41; &#123;
        
        this.depto = depto;
        
    &#125;
    
    
    
    
    
    /**
     * Return the cargo.
     */
    public String getCargo&#40;&#41; &#123;
        
        return &#40;this.cargo&#41;;
        
    &#125;
    
    
    /**
     * Set the cargo.
     *
     * @param cargo The new cargo
     */
    public void setCargo&#40;String cargo&#41; &#123;
        
        this.cargo = cargo;
        
    &#125;
    
    
    
    
    
    /**
     * Return the dddcom.
     */
    public String getDddcom&#40;&#41; &#123;
        
        return &#40;this.dddcom&#41;;
        
    &#125;
    
    
    /**
     * Set the dddcom.
     *
     * @param dddcom The new dddcom
     */
    public void setDddcom&#40;String dddcom&#41; &#123;
        
        this.dddcom = dddcom;
        
    &#125;
    
    
    
    
    
    /**
     * Return the telefonecom.
     */
    public String getTelefonecom&#40;&#41; &#123;
        
        return &#40;this.telefonecom&#41;;
        
    &#125;
    
    
    /**
     * Set the telefonecom.
     *
     * @param telefonecom The new telefonecom
     */
    public void setTelefonecom&#40;String telefonecom&#41; &#123;
        
        this.telefonecom = telefonecom;
        
    &#125;
    
    
    
    
    // --------------------------------------------------------- Public Methods
    
    
    /**
     * Reset all properties to their default values.
     *
     * @param mapping The mapping used to select this instance
     * @param request The servlet request we are processing
     */
    public void reset&#40;ActionMapping mapping, HttpServletRequest request&#41; &#123;
        
        this.nome        = null;
        this.dddres      = null;
        this.telefoneres = null;
        this.endereco    = null;
        this.bairro      = null;
        this.cidade      = null;
        this.estado      = null;
        this.cep         = null;
        this.usuario     = null;
        this.email       = null;
        this.senha       = null;
        this.empresa     = null;
        this.depto       = null;
        this.cargo       = null;
        this.dddcom      = null;
        this.telefonecom = null;
    &#125;
    
    
    /**
     * Validate the properties that have been set from this HTTP request,
     * and return an &lt;code&gt;ActionErrors&lt;/code&gt; object that encapsulates any
     * validation errors that have been found.  If no errors are found, return
     * &lt;code&gt;null&lt;/code&gt; or an &lt;code&gt;ActionErrors&lt;/code&gt; object with no
     * recorded error messages.
     *
     * @param mapping The mapping used to select this instance
     * @param request The servlet request we are processing
     */
    public ActionErrors validate&#40;ActionMapping mapping,
    HttpServletRequest request&#41; &#123;
        
        ActionErrors errors = new ActionErrors&#40;&#41;;
        if &#40;&#40;nome == null&#41; || &#40;nome.length&#40;&#41; &lt; 1&#41;&#41;
            errors.add&#40;&quot;nome&quot;, new ActionError&#40;&quot;error.nome.required&quot;&#41;&#41;;
        if &#40;&#40;dddres == null&#41; || &#40;dddres.length&#40;&#41; &lt; 1&#41;&#41;
            errors.add&#40;&quot;dddres&quot;, new ActionError&#40;&quot;error.dddres.required&quot;&#41;&#41;;
        if &#40;&#40;telefoneres == null&#41; || &#40;telefoneres.length&#40;&#41; &lt; 1&#41;&#41;
            errors.add&#40;&quot;telefoneres&quot;, 
                new ActionError&#40;&quot;error.telefoneres.required&quot;&#41;&#41;;
        if &#40;&#40;endereco == null&#41; || &#40;endereco.length&#40;&#41; &lt; 1&#41;&#41;
            errors.add&#40;&quot;endereco&quot;, new ActionError&#40;&quot;error.endereco.required&quot;&#41;&#41;;
        if &#40;&#40;bairro == null&#41; || &#40;bairro.length&#40;&#41; &lt; 1&#41;&#41;
            errors.add&#40;&quot;bairro&quot;, new ActionError&#40;&quot;error.bairro.required&quot;&#41;&#41;;
        if &#40;&#40;cidade == null&#41; || &#40;cidade.length&#40;&#41; &lt; 1&#41;&#41;
            errors.add&#40;&quot;cidade&quot;, new ActionError&#40;&quot;error.cidade.required&quot;&#41;&#41;;
        if &#40;&#40;estado == null&#41; || &#40;estado.length&#40;&#41; &lt; 1&#41;&#41;
            errors.add&#40;&quot;estado&quot;, new ActionError&#40;&quot;error.estado.required&quot;&#41;&#41;;
        if &#40;&#40;cep == null&#41; || &#40;cep.length&#40;&#41; &lt; 1&#41;&#41;
            errors.add&#40;&quot;cep&quot;, new ActionError&#40;&quot;error.cep.required&quot;&#41;&#41;;
        if &#40;&#40;usuario == null&#41; || &#40;usuario.length&#40;&#41; &lt; 1&#41;&#41;
            errors.add&#40;&quot;usuario&quot;, new ActionError&#40;&quot;error.usuario.required&quot;&#41;&#41;;
        if &#40;&#40;email == null&#41; || &#40;email.length&#40;&#41; &lt; 1&#41;&#41;
            errors.add&#40;&quot;email&quot;, new ActionError&#40;&quot;error.email.required&quot;&#41;&#41;;
        else &#123;
	    int atSign = email.indexOf&#40;&quot;@&quot;&#41;;
	    if &#40;&#40;atSign &lt; 1&#41; || &#40;atSign &gt;= &#40;email.length&#40;&#41; - 1&#41;&#41;&#41;
		errors.add&#40;&quot;email&quot;,
                           new ActionError&#40;&quot;error.email.format&quot;,
                                           email&#41;&#41;;
	&#125;        
        if &#40;&#40;senha == null&#41; || &#40;senha.length&#40;&#41; &lt; 1&#41;&#41;
            errors.add&#40;&quot;senha&quot;, new ActionError&#40;&quot;error.senha.required&quot;&#41;&#41;;
        
        return errors;        
    &#125;    
&#125;

:arrow: JSP frmUsuario

&lt;%@ page language=&quot;java&quot; %&gt;
&lt;%@ taglib uri=&quot;/WEB-INF/struts-html.tld&quot; prefix=&quot;html&quot; %&gt;
&lt;%@ taglib uri=&quot;/WEB-INF/struts-bean.tld&quot; prefix=&quot;bean&quot; %&gt;

&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;&gt;

&lt;html&#58;html&gt;
    &lt;head&gt;
        &lt;title&gt;&lt;bean&#58;message key=&quot;usuario.title&quot;/&gt;&lt;/title&gt;
        &lt;html&#58;base/&gt;
        &lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot; 
                src=&quot;cotacao-on-line.js&quot;&gt;
        &lt;/script&gt;
    &lt;/head&gt;

    &lt;body&gt;
    &lt;html&#58;errors/&gt;
        &lt;html&#58;form action=&quot;/usuario&quot; focus=&quot;nome&quot; onsubmit=&quot;return valida_frmusuario&#40;&#41;&quot;&gt;
            &lt;table&gt;
                &lt;tr&gt;
                    &lt;td colspan=&quot;2&quot;&gt;&lt;h3&gt;&lt;bean&#58;message key=&quot;usuario.alerta&quot;/&gt;&lt;/h3&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;&lt;bean&#58;message key=&quot;usuario.prompt.nome&quot;/&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;html&#58;text property=&quot;nome&quot; size=&quot;60&quot; maxlength=&quot;60&quot;/&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;&lt;bean&#58;message key=&quot;usuario.prompt.dddres&quot;/&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;html&#58;text property=&quot;dddres&quot; size=&quot;2&quot; maxlength=&quot;2&quot;/&gt;
                        &amp;nbsp;&amp;nbsp;
                        &lt;bean&#58;message key=&quot;usuario.prompt.telefoneres&quot;/&gt;
                        &lt;html&#58;text property=&quot;telefoneres&quot; size=&quot;20&quot; maxlength=&quot;20&quot;/&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;&lt;bean&#58;message key=&quot;usuario.prompt.endereco&quot;/&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;html&#58;text property=&quot;endereco&quot; size=&quot;60&quot; maxlength=&quot;60&quot;/&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;&lt;bean&#58;message key=&quot;usuario.prompt.bairro&quot;/&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;html&#58;text property=&quot;bairro&quot; size=&quot;60&quot; maxlength=&quot;60&quot;/&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;&lt;bean&#58;message key=&quot;usuario.prompt.cidade&quot;/&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;html&#58;text property=&quot;cidade&quot; size=&quot;60&quot; maxlength=&quot;60&quot;/&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;&lt;bean&#58;message key=&quot;usuario.prompt.estado&quot;/&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;html&#58;select property=&quot;estado&quot; size=&quot;0&quot;&gt;
                    &lt;option value=&quot;&quot; selected&gt;Escolha seu estado
                    &lt;option value=&quot;AC&quot;&gt;AC&lt;/option&gt;
                    &lt;option value=&quot;AL&quot;&gt;AL&lt;/option&gt;
                    &lt;option value=&quot;AM&quot;&gt;AM&lt;/option&gt;
                    &lt;option value=&quot;AP&quot;&gt;AP&lt;/option&gt;
                    &lt;option value=&quot;BA&quot;&gt;BA&lt;/option&gt;
                    &lt;option value=&quot;CE&quot;&gt;CE&lt;/option&gt;
                    &lt;option value=&quot;DF&quot;&gt;DF&lt;/option&gt;
                    &lt;option value=&quot;ES&quot;&gt;ES&lt;/option&gt;
                    &lt;option value=&quot;GO&quot;&gt;GO&lt;/option&gt;
                    &lt;option value=&quot;MA&quot;&gt;MA&lt;/option&gt;
                    &lt;option value=&quot;MG&quot;&gt;MG&lt;/option&gt;
                    &lt;option value=&quot;MS&quot;&gt;MS&lt;/option&gt;
                    &lt;option value=&quot;MT&quot;&gt;MT&lt;/option&gt;
                    &lt;option value=&quot;PA&quot;&gt;PA&lt;/option&gt;
                    &lt;option value=&quot;PB&quot;&gt;PB&lt;/option&gt;
                    &lt;option value=&quot;PE&quot;&gt;PE&lt;/option&gt;
                    &lt;option value=&quot;PI&quot;&gt;PI&lt;/option&gt;
                    &lt;option value=&quot;PR&quot;&gt;PR&lt;/option&gt;
                    &lt;option value=&quot;RJ&quot;&gt;RJ&lt;/option&gt;
                    &lt;option value=&quot;RN&quot;&gt;RN&lt;/option&gt;
                    &lt;option value=&quot;RO&quot;&gt;RO&lt;/option&gt;
                    &lt;option value=&quot;RR&quot;&gt;RR&lt;/option&gt;
                    &lt;option value=&quot;RS&quot;&gt;RS&lt;/option&gt;
                    &lt;option value=&quot;SC&quot;&gt;SC&lt;/option&gt;
                    &lt;option value=&quot;SE&quot;&gt;SE&lt;/option&gt;
                    &lt;option value=&quot;SP&quot;&gt;SP&lt;/option&gt;
                    &lt;option value=&quot;TO&quot;&gt;TO&lt;/option&gt;
                    &lt;/html&#58;select&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td colspan=&quot;2&quot;&gt;
                    &lt;hr align=&quot;center&quot; width=&quot;100%&quot;&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;&lt;bean&#58;message key=&quot;usuario.prompt.usuario&quot;/&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;html&#58;text property=&quot;usuario&quot; size=&quot;60&quot; maxlength=&quot;60&quot;/&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;&lt;bean&#58;message key=&quot;usuario.prompt.email&quot;/&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;html&#58;text property=&quot;email&quot; size=&quot;60&quot; maxlength=&quot;60&quot;/&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;&lt;bean&#58;message key=&quot;usuario.prompt.senha&quot;/&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;input type=&quot;password&quot; name=&quot;senha&quot; size=&quot;20&quot; maxlength=&quot;60&quot;/&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;&lt;bean&#58;message key=&quot;usuario.prompt.senha2&quot;/&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;input type=&quot;password&quot; name=&quot;senha2&quot; size=&quot;20&quot; maxlength=&quot;60&quot;/&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td colspan=&quot;2&quot;&gt;
                    &lt;hr align=&quot;center&quot; width=&quot;100%&quot;&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;&lt;bean&#58;message key=&quot;usuario.prompt.empresa&quot;/&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;html&#58;text property=&quot;empresa&quot; size=&quot;60&quot; maxlength=&quot;60&quot;/&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;&lt;bean&#58;message key=&quot;usuario.prompt.dddcom&quot;/&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;html&#58;text property=&quot;dddcom&quot; size=&quot;2&quot; maxlength=&quot;2&quot;/&gt;
                        &amp;nbsp;&amp;nbsp;
                        &lt;bean&#58;message key=&quot;usuario.prompt.telefonecom&quot;/&gt;
                        &lt;html&#58;text property=&quot;telefonecom&quot; size=&quot;20&quot; maxlength=&quot;20&quot;/&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;&lt;bean&#58;message key=&quot;usuario.prompt.depto&quot;/&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;html&#58;text property=&quot;depto&quot; size=&quot;60&quot; maxlength=&quot;60&quot;/&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;&lt;bean&#58;message key=&quot;usuario.prompt.cargo&quot;/&gt;&lt;/td&gt;
                    &lt;td&gt;&lt;html&#58;text property=&quot;cargo&quot; size=&quot;60&quot; maxlength=&quot;60&quot;/&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr align=&quot;center&quot;&gt;
                    &lt;td colspan=&quot;2&quot;&gt;
                        &lt;html&#58;submit property=&quot;submit&quot;&gt;
                            &lt;bean&#58;message key=&quot;button.submit&quot;/&gt;&amp;nbsp;&amp;nbsp;
                        &lt;/html&#58;submit&gt;
                        &lt;html&#58;reset&gt;
                            &lt;bean&#58;message key=&quot;button.reset&quot;/&gt;
                        &lt;/html&#58;reset&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
            &lt;/table&gt;
        &lt;/html&#58;form&gt;
    &lt;/body&gt;
&lt;/html&#58;html&gt;
urubatan

bom, olhando por cima, não consegui achar onde poderiam estar aparecendo estes dois null, onde eles aparecem??

fsa_net

Elas aparecem acima do form.

urubatan

tenta retornar null no validate do actionForm caso não ocorra erro nenhum :slight_smile:

fsa_net

OK!

Vou fazer isto agora.

fsa_net

Continua aparecendo… null null

Quando clico em Enviar, ocorre o processamento e depois os dados permanecerm na tela e surgem os null’s. :frowning:

Veja o código HTML gerado pelo JSP

&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt;

&lt;html lang="en"&gt;
    &lt;head&gt;
        &lt;title&gt;DMS - Cadastro de usuario&lt;/title&gt;
        &lt;base href="http&#58;//s1&#58;8088/cotacaoonline/frmUsuario.jsp"&gt;
        &lt;script language="javascript" type="text/javascript" 
                src="cotacao-on-line.js"&gt;
        &lt;/script&gt;

    &lt;/head&gt;

    &lt;body&gt;
    
        &lt;form name="usuarioForm" method="POST" action="/cotacaoonline/usuario.do" onsubmit="return valida_frmusuario&#40;&#41;"&gt;
            &lt;table&gt;
                &lt;tr&gt;
                    &lt;td colspan="2"&gt;&lt;h3&gt;Aten&amp;ccedil;&amp;atilde;o - campos marcados com asterisco &#40;*&#41; s&amp;atilde;o obrigat&amp;oacute;rios!&lt;/h3&gt;

                    &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;Nome&lt;/td&gt;
                    &lt;td&gt;&lt;input type="text" name="nome" maxlength="60" size="60" value=""&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;DDD&lt;/td&gt;

                    &lt;td&gt;&lt;input type="text" name="dddres" maxlength="2" size="2" value=""&gt;
                        &amp;nbsp;&amp;nbsp;
                        Telefone
                        &lt;input type="text" name="telefoneres" maxlength="20" size="20" value=""&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;Endere&amp;ccedil;o&lt;/td&gt;

                    &lt;td&gt;&lt;input type="text" name="endereco" maxlength="60" size="60" value=""&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;Bairro&lt;/td&gt;
                    &lt;td&gt;&lt;input type="text" name="bairro" maxlength="60" size="60" value=""&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;Cidade&lt;/td&gt;

                    &lt;td&gt;&lt;input type="text" name="cidade" maxlength="60" size="60" value=""&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;Estado&lt;/td&gt;
                    &lt;td&gt;&lt;select name="estado" size="0"&gt;&lt;option value="" selected&gt;Escolha seu estado
                    &lt;option value="AC"&gt;AC&lt;/option&gt;
                    &lt;option value="AL"&gt;AL&lt;/option&gt;
                    &lt;option value="AM"&gt;AM&lt;/option&gt;

                    &lt;option value="AP"&gt;AP&lt;/option&gt;
                    &lt;option value="BA"&gt;BA&lt;/option&gt;
                    &lt;option value="CE"&gt;CE&lt;/option&gt;
                    &lt;option value="DF"&gt;DF&lt;/option&gt;
                    &lt;option value="ES"&gt;ES&lt;/option&gt;
                    &lt;option value="GO"&gt;GO&lt;/option&gt;

                    &lt;option value="MA"&gt;MA&lt;/option&gt;
                    &lt;option value="MG"&gt;MG&lt;/option&gt;
                    &lt;option value="MS"&gt;MS&lt;/option&gt;
                    &lt;option value="MT"&gt;MT&lt;/option&gt;
                    &lt;option value="PA"&gt;PA&lt;/option&gt;
                    &lt;option value="PB"&gt;PB&lt;/option&gt;

                    &lt;option value="PE"&gt;PE&lt;/option&gt;
                    &lt;option value="PI"&gt;PI&lt;/option&gt;
                    &lt;option value="PR"&gt;PR&lt;/option&gt;
                    &lt;option value="RJ"&gt;RJ&lt;/option&gt;
                    &lt;option value="RN"&gt;RN&lt;/option&gt;
                    &lt;option value="RO"&gt;RO&lt;/option&gt;

                    &lt;option value="RR"&gt;RR&lt;/option&gt;
                    &lt;option value="RS"&gt;RS&lt;/option&gt;
                    &lt;option value="SC"&gt;SC&lt;/option&gt;
                    &lt;option value="SE"&gt;SE&lt;/option&gt;
                    &lt;option value="SP"&gt;SP&lt;/option&gt;
                    &lt;option value="TO"&gt;TO&lt;/option&gt;&lt;/select&gt;&lt;/td&gt;

                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td colspan="2"&gt;
                    &lt;hr align="center" width="100%"&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;Usu&amp;aacute;rio&lt;/td&gt;

                    &lt;td&gt;&lt;input type="text" name="usuario" maxlength="60" size="60" value=""&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;E-mail&lt;/td&gt;
                    &lt;td&gt;&lt;input type="text" name="email" maxlength="60" size="60" value=""&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;Senha&lt;/td&gt;

                    &lt;td&gt;&lt;input type="password" name="senha" size="20" maxlength="60"/&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;Redigite a senha&lt;/td&gt;
                    &lt;td&gt;&lt;input type="password" name="senha2" size="20" maxlength="60"/&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td colspan="2"&gt;

                    &lt;hr align="center" width="100%"&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;Empresa&lt;/td&gt;
                    &lt;td&gt;&lt;input type="text" name="empresa" maxlength="60" size="60" value=""&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;

                    &lt;td&gt;DDD&lt;/td&gt;
                    &lt;td&gt;&lt;input type="text" name="dddcom" maxlength="2" size="2" value=""&gt;
                        &amp;nbsp;&amp;nbsp;
                        Telefone
                        &lt;input type="text" name="telefonecom" maxlength="20" size="20" value=""&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;Departamento&lt;/td&gt;

                    &lt;td&gt;&lt;input type="text" name="depto" maxlength="60" size="60" value=""&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;Cargo&lt;/td&gt;
                    &lt;td&gt;&lt;input type="text" name="cargo" maxlength="60" size="60" value=""&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr align="center"&gt;
                    &lt;td colspan="2"&gt;

                        &lt;input type="submit" name="submit" value="Enviar&amp;nbsp;&amp;nbsp;"&gt;
                        &lt;input type="reset" name="reset" value="Limpar Campos"&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
            &lt;/table&gt;
        &lt;/form&gt;
&lt;script language="JavaScript" type="text/javascript"&gt;
  &lt;!--
    document.forms&#91;"usuarioForm"&#93;.elements&#91;"nome"&#93;.focus&#40;&#41;
  // --&gt;
&lt;/script&gt;

    &lt;/body&gt;

&lt;/html&gt;
fsa_net

Urubatan,

O processo de coleta de dados do forms pelo Struts é :
[list]
1-Os dados são transferidos para o FormBean (UsuarioForm);

2-O Action acessa objetos de negócios e model para salvar os dados (UsuarioAction)

3-E no Controller, que é configurado pelo arquivo struts-config.xml, faço o redirecionamento para outra página, neste caso quero mudar para o Index.jsp, após efetuar o cadastro.
[/list]

Então o problema de aparecerm os nulls, deve estar na camada Controller :idea:

urubatan

isto é estranho, não estou conseguindo localizar os nullTML que você enviou, me mostra onde eles aparecem que fica mais facil de identificar qual é o problema :slight_smile:

fsa_net

Eles aparecem antes do formulário....

Código HTML
&lt;body&gt;
    null
null

        &lt;form name=&quot;usuarioForm&quot; method=&quot;POST&quot; action=&quot;/cotacaoonline/usuario.do&quot; onsubmit=&quot;return valida_frmusuario&#40;&#41;&quot;&gt;
            &lt;table&gt;
urubatan

bom, os null, com certeza estão sendo gerados pelo ActionErrors, vou testar isto hoje a noite aqui em casa para ver o que podeser, assim não estou conseguindo localizar :frowning:

assim que eu descobrir o problema te aviso :slight_smile:

fsa_net

Descobri porquê aparecem os null… A validação dá um erro e deveria aparecer uma mensagem assim:

[size=“18”][color=“red”]Validation Error[/color][/size]
You must correct the following error(s) before proceeding:
Invalid username and/or password, please try again

Só que como eu não sei como configurar mensagens de erro, ele se perde no momento de buscar a descrição do erro e surgem os nulls.

Criado 18 de março de 2003
Ultima resposta 20 de mar. de 2003
Respostas 23
Participantes 5