Nao estou conseguindo utilizar duas ações para o mesmo Bean

2 respostas
I

Pessoa,

Estou fazendo um trabalho em Struts…Nao tenho experiencia ainda. Vejam duas ações no meu XML

<!--ESTA ACAO REFERE-SE AO ATO De BUSCAR USUARIO NO SISTEMA   -->
            <action input="/BuscarUsuario.jsp" name="BeanUsuario"  path="/BeanUsuario" scope="request" type="controle.ActionBuscarUsuario">
             <forward name="UsuarioEncontradonaBase" path="/UsuarioEncontrado.jsp"/>
             </action>

              <!--ESTA ACAO REFERE-SE AO ATO De REMOVER USUARIO NO SISTEMA   -->
            <action input="/UsuarioEncontrado.jsp" name="BeanUsuario"  path="/BeanUsuario" scope="request" type="controle.ActionRemoverUsuario">
                <forward name="UsuarioRemovido" path="/UsuarioRemovidoSucesso.jsp"/>
                </action>

Vamos lá …o que acontece

1- Quando o arquivo está dessa forma … no momento que eu mando buscar um usuario no sistema ele executa o esse encaminhamento

2 - Quando eu tiro a ação por completa

, ele funciona normalmente
trazendo o usuario cadastrado

3 - Estou utilizando assim, por q nao quero criar mais um Bean q tenha os mesmos atributos…quer dizer…tenho uma solução q a meu ver é um armengo…
deve ter algum detalhe que eu possa fazer…assim eu imagino!

Obrigado a todos q puderem ajudar

Abraços

2 Respostas

B

Como está seu BeanUsuario???
Ele é subclasse de ActionForm?

Postanto somente o xml fica meio difícil… dá uma especificada melhor!!
;p

I

Olá Biro..Obrigado pela ajuda

Bom..meu BeanUsuario

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package negocio;



/**
 *
 * @author Rod
 */
public class BeanUsuario extends org.apache.struts.action.ActionForm {


  private String nome;
    private String logradouro;
    private String bairro;
    private int cidade;
    private int estado;
    private String telefone;
    private String cpf;
    private String email;
    private int tipo;
    private String curso;
    private int id;
    private String senha;
    private String login;

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }


    public String getBairro() {
        return bairro;
    }

    public void setBairro(String bairro) {
        this.bairro = bairro;
    }

    public int getCidade() {
        return cidade;
    }

    public void setCidade(int cidade) {
        this.cidade = cidade;
    }

    public String getCpf() {
        return cpf;
    }

    public void setCpf(String cpf) {
        this.cpf = cpf;
    }

    public String getCurso() {
        return curso;
    }

    public void setCurso(String curso) {
        this.curso = curso;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public int getEstado() {
        return estado;
    }

    public void setEstado(int estado) {
        this.estado = estado;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getLogradouro() {
        return logradouro;
    }

    public void setLogradouro(String logradouro) {
        this.logradouro = logradouro;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getTelefone() {
        return telefone;
    }

    public void setTelefone(String telefone) {
        this.telefone = telefone;
    }

    public int getTipo() {
        return tipo;
    }

    public void setTipo(int tipo) {
        this.tipo = tipo;
    }


    public String getSenha() {
        return senha;
    }

    public void setSenha(String senha) {
        this.senha = senha;
    }

   


 






   
}

Meu XML completo

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
          "http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd">


<struts-config>
    <form-beans>
            <form-bean name="BeanUsuario" type="negocio.BeanUsuario"/>
            <form-bean name="BeanLogin" type="negocio.BeanLogin"/>
    
    </form-beans>
    
    <global-exceptions>
    
    </global-exceptions>

    <global-forwards>
        <forward name="welcome"  path="/Welcome.do"/>
        <forward name="ERROLOGIN" path="/ErroLogin.jsp"/>
        <forward name="LOGADO" path="/Sucesso.jsp"/>
        <forward name="CADASTROUSEROK" path="/UsuarioCadastradoSucesso.jsp"/>

       </global-forwards>

    <action-mappings>
        <action path="/Welcome" forward="/welcomeStruts.jsp"/>

        <!--ESTA ACAO REFERE-SE AO ATO DE LOGAR NO SISTEMA   -->
         <action input="/welcomeStruts.jsp" name="BeanLogin" path="/BeanLogin" scope="session" type="controle.ActionLogar">
            <forward name="LoginOK" path="/Sucesso.jsp"/>
            <forward name="ErroLogin" path="/ErroLogin.jsp"/>
          </action>

            <!--ESTA ACAO REFERE-SE AO ATO De CADASTRAR USUARIO NO SISTEMA   -->
            <action input="/CadastrarUsuario.jsp" name="BeanUsuario" path="/BeanUsuario" scope="request" type="controle.ActionCadastrarUser">
              <forward name="UsuarioCadastroSucesso" path="/UsuarioCadastradoSucesso.jsp"/>
            </action>

            <!--ESTA ACAO REFERE-SE AO ATO De BUSCAR USUARIO NO SISTEMA   -->
            <action input="/BuscarUsuario.jsp" name="BeanUsuario"  path="/BeanUsuario" scope="request" type="controle.ActionBuscarUsuario">
             <forward name="UsuarioEncontradonaBase" path="/UsuarioEncontrado.jsp"/>
             </action>

              <!--ESTA ACAO REFERE-SE AO ATO De REMOVER USUARIO NO SISTEMA   -->
            <action input="/UsuarioEncontrado.jsp" name="BeanUsuario"  path="/BeanUsuario" scope="request" type="controle.ActionRemoverUsuario">
                <forward name="UsuarioRemovido" path="/UsuarioRemovidoSucesso.jsp"/>
                </action>

            
            

    </action-mappings>
    
    <controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>

    <message-resources parameter="com/myapp/struts/ApplicationResource"/>    
    
    <!-- ========================= Tiles plugin ===============================-->
    <!--
    This plugin initialize Tiles definition factory. This later can takes some
    parameters explained here after. The plugin first read parameters from
    web.xml, thenoverload them with parameters defined here. All parameters
    are optional.
    The plugin should be declared in each struts-config file.
    - definitions-config: (optional)
    Specify configuration file names. There can be several comma
    separated file names (default: ?? )
    - moduleAware: (optional - struts1.1)
    Specify if the Tiles definition factory is module aware. If true
    (default), there will be one factory for each Struts module.
    If false, there will be one common factory for all module. In this
    later case, it is still needed to declare one plugin per module.
    The factory will be initialized with parameters found in the first
    initialized plugin (generally the one associated with the default
    module).
    true : One factory per module. (default)
    false : one single shared factory for all modules
    - definitions-parser-validate: (optional)
    Specify if xml parser should validate the Tiles configuration file.
    true : validate. DTD should be specified in file header (default)
    false : no validation

    Paths found in Tiles definitions are relative to the main context.
    -->
    <plug-in className="org.apache.struts.tiles.TilesPlugin" >
        <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />      
        <set-property property="moduleAware" value="true" />
    </plug-in>
    
    <!-- ========================= Validator plugin ================================= -->
    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
        <set-property
            property="pathnames"
            value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
    </plug-in>
  
</struts-config>
JSP que retorna a busca do Usuario
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<html:html lang="true">
    <html>
        <head>
            <title>Sistema de Controle de Trabalhos de Conclusao de Curso</title>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <link href="principal.css" rel="stylesheet" type="text/css" />
            <html:base/>
        </head>
        <body>

            <div id="main">
                <div id="topo"></div>
                <div id="centro" >
                    <br>

                    <html:form action="/BeanUsuario">


                        <table border="1" align="center">
                           
                                <tr>
                                    <th>Email</th>
                                    <th>Nome</th>
                                    <th>Tipo</th>
                                    <th>Curso</th>
                                </tr>

                            <tr>

                            <td> <html:text name="USUARIOENCONTRADO" property="email"/></td>
                             <td> <html:text name="USUARIOENCONTRADO" property="nome"/></td>
                               <td> <html:text name="USUARIOENCONTRADO" property="id"/></td>
                            </tr>
                             
                        </table>
                         

                           


                        <div id="btcaduser"><html:submit property="btremover" value="Remover"/></div>
                        <div id="btlimpar"><html:reset property="btlimpar" value="Limpar"/></div>



                    </html:form>

                </div>


            </div>







        </body>

    </html:html>
Ação de Buscar Usuario
public class ActionBuscarUsuario extends org.apache.struts.action.Action {
    
    /* forward name="success" path="" */
    private static final String BUSCAUSUARIOPOREMAIL = "UsuarioEncontradonaBase";
    
  
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        BeanUsuario usuario =  ( BeanUsuario) form;
        Dao con = new Dao();
        BeanUsuario usuarioencontrado = con.BuscarUsuarioporEmail(usuario);

        request.setAttribute("USUARIOENCONTRADO", usuarioencontrado);

        return mapping.findForward(BUSCAUSUARIOPOREMAIL);
}
}
Ação de Remover Usuario
private static final String REMOVIDO = "UsuarioRemovido";
    
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

       BeanUsuario usuario =  ( BeanUsuario ) form;
       Dao con = new Dao();
       con.RemoverUsuario(usuario);

        return mapping.findForward(REMOVIDO);

Obrigado mais uma vez!!

Criado 13 de novembro de 2009
Ultima resposta 13 de nov. de 2009
Respostas 2
Participantes 2