Daniel Calderon Mori
Daniel Calderon Mori

Reputation: 5776

Pass selected value from a select tag to an action using Struts2 and Dojo

I'm trying to pass the selected value of a select tag to an action through ajax when the onchange event is triggered but, for some reason, the action receives the parameter as null.

Here is the code of the jsp:

<%@taglib prefix="s" uri="/struts-tags" %>
<%@taglib prefix="sx" uri="/struts-dojo-tags" %>
<div id="navegacion_proyectos">
    <s:select name="id_proyecto_actual" id="proyecto_actual_select" list="proyectos" listValue="titulo_proyecto" listKey="id_proyecto"/>
    <s:url id="cambiar_proyecto_actual_url" value="/cambiar_proyecto_actual.action" />
    <sx:bind sources="proyecto_actual_select" events="onchange" href="%{cambiar_proyecto_actual_url}" />
</div>

And here is the code of the action:

public class BLProyecto extends ActionSupport {

    private String id_proyecto_actual;

    public String cambiarProyectoActual() {

        Map sesion = ActionContext.getContext().getSession();
        sesion.put("proyecto_actual", id_proyecto_actual);

        return SUCCESS;
    }
    public String getId_proyecto_actual() {
        return id_proyecto_actual;
    }

    public void setId_proyecto_actual(String id_proyecto_actual) {
        this.id_proyecto_actual = id_proyecto_actual;
    }

}

I'm debbuging the code and the id_proyecto_actual parameter is shown as null. What do you think is the problem?

Upvotes: 0

Views: 2677

Answers (1)

Daniel Calderon Mori
Daniel Calderon Mori

Reputation: 5776

Thank you all, i found the answer. Instead of following an url when the event is triggered, i just submit a form. Like this:

<%@taglib prefix="s" uri="/struts-tags" %>
<%@taglib prefix="sx" uri="/struts-dojo-tags" %>
<div id="navegacion_proyectos">
    <s:form id="cambiar_proyecto_actual_form" action="cambiar_proyecto_actual">
        <s:select name="id_proyecto_actual" id="proyecto_actual_select" list="proyectos" listValue="titulo_proyecto" listKey="id_proyecto"/>
    </s:form>
    <sx:bind sources="proyecto_actual_select" formId="cambiar_proyecto_actual_form" targets="pantalla_principal" events="onchange" />
</div>

Upvotes: 1

Related Questions