Pass JSP value to Action

1

I have the following jsp below, in it the user chooses the state, while choosing the state my javascript shows in an alert with the information I want to pass to the Action to follow the validations and takes the user to another action " -stat.do, "this is occurring, when I get down to the Action I want, but I can not in any way bring the value of the Action to the" location-

  <script>
    function mantemEstado(){

        var sgEstado = document.localizarLojasForm["sgEstado"].value;
        alert(sgEstado);
        form.action = "<c:url value="/localiza-lojas-estado.do"/>";
        form.submit();
    }
    </script>

    <div class="fr">

        <div class="caminho-link">
            <a href="#" class="caminho-link-1" target="_blank">Home </a> <font
                face="Arial, Helvetica, sans-serif" color="#007088"
                style="font-weight: bold; font-size: 12px;"> >> </font> <a href="#"
                class="caminho-link-2" target="_blank">Localizar Lojas</a>
        </div>

        <div class="slocator-box">
            <html:form action="/localiza-lojas.do" method="post" styleId="cadastroCliente2">

<html:hidden property="sgEstado"/>

                <div class="slocator-estado">
                    <html:select tabindex="2" onkeypress="Enter(this.tabIndex, event)" property="sgEstado" styleClass="w80" value="Digite seu E-mail" onchange="javascript:mantemEstado();"     >
                        <html:options collection="listaEstados" property="sgEstado" labelProperty="sgEstado" />
                    </html:select>
                </div>


                <div class="slocator-cidade">
                    <html:select tabindex="2" onkeypress="Enter(this.tabIndex, event)" property="dsCidade" styleClass="w80">
                        <html:options collection="listaCidades" property="dsCidade" labelProperty="dsCidade"  />
                    </html:select>
                </div>

                <html:hidden property="sgEstado"/>
                <div class="slocator-bairro">
                    <html:select tabindex="2" onkeypress="Enter(this.tabIndex, event)" property="dsBairro" styleClass="w80">
                        <html:options collection="listaBairros" property="dsBairro" labelProperty="dsBairro" />
                    </html:select>
                </div>
    
asked by anonymous 21.10.2014 / 15:45

1 answer

1

Change this:

<html:hidden property="sgEstado"/>

For this reason:

<input type="hidden"  name="sgEstado"  id="sgEstado"/>

Include this in your script:

document.getElementById('sgEstado').value = sgEstado;

Go to your Actions class and declare this (with the getters and setters):

private String sgEstado;

Explanation:

JavaScript uses the id to locate the hidden tag and set its value. Struts2 uses name to define the value of the string (that is, the tag name and variable name must be identical).

    
23.10.2014 / 17:27