Form being rendered with wrong action attribute

0

I'm using the spring form tags to render the forms present in my views, but I'm having problems because they are being generated with the wrong action attribute.

In my controller, I have the method:

@RequestMapping(value="altera/{theString}")
@PreAuthorize("hasPermission(#user, 'altera_'+#this.this.name)")
public ModelAndView altera(@PathVariable String theString) {
    int id = Integer.valueOf(theString).intValue();
    return new ModelAndView("privado/"+this.getName()+"/altera", "command", serv.listagem(id));
}

which will direct the application to this view:

private / <nome_da_classe> / alias.jsp

<jsp:include page="../../common/altera.jsp">
    <jsp:param name="action" value="/Usuario/altera"/>

    <jsp:param name="elements" value="login"/>
    <jsp:param name="elements" value="senha"/>
    <jsp:param name="elements" value="first_name"/>
    <jsp:param name="elements" value="last_name"/>
    <jsp:param name="elements" value="email"/>

    <jsp:param name="label" value="Login"/>
    <jsp:param name="label" value="Senha"/>
    <jsp:param name="label" value="Nome"/>
    <jsp:param name="label" value="Sobrenome"/>
    <jsp:param name="label" value="E-mail"/>

    <jsp:param name="type" value="text"/>
    <jsp:param name="type" value="password"/>
    <jsp:param name="type" value="text"/>
    <jsp:param name="type" value="text"/>
    <jsp:param name="type" value="email"/>
</jsp:include>

common / alias.jsp

<%@ include file="../include/header_interno.jsp" %>

<form:form class="form" role="form" method="post">

    <table>
        <c:forEach var="item" items="${paramValues.elements}" varStatus="status">
        <tr>
            <td><form:label path="${item}">${paramValues.label[status.index]}</form:label></td>
            <td><form:input path="${item}" type="${paramValues.type[status.index]}" /></td> 
        </tr>
        </c:forEach>
        <tr>
            <td colspan="2">
                <button type="submit" formaction="${action}" class="btn btn-lg btn-primary">Alterar</button>
            </td>
        </tr>
    </table>

</form:form>

<%@ include file="../include/result.jsp" %>

<%@ include file="../include/footer_interno.jsp" %>

that should direct the data entered in the fields to this other controller method:

@RequestMapping(value="altera", method=RequestMethod.POST)
@ResponseBody
public String altera(@ModelAttribute("object") E object, BindingResult result) {
    if(serv.altera(object))
        return "yes";
    else
        return "not";
}

but the html is being rendered to this:

<html>
<head>
<title></title>

<body>


<form id="command" role="form" class="form" action="/blog/Usuario/altera/2" method="post">

    <table>

        <tr>
            <td><label for="login">Login</label></td>
            <td><input id="login" name="login" type="text" value="teste"/></td> 
        </tr>

        <tr>
            <td><label for="senha">Senha</label></td>
            <td><input id="senha" name="senha" type="password" value="123"/></td> 
        </tr>

        <tr>
            <td><label for="first_name">Nome</label></td>
            <td><input id="first_name" name="first_name" type="text" value="Usuario"/></td> 
        </tr>

        <tr>
            <td><label for="last_name">Sobrenome</label></td>
            <td><input id="last_name" name="last_name" type="text" value="Primeiro"/></td> 
        </tr>

        <tr>
            <td><label for="email">E-mail</label></td>
            <td><input id="email" name="email" type="email" value="[email protected]"/></td> 
        </tr>

        <tr>
            <td colspan="2">
                <button type="submit" formaction="" class="btn btn-lg btn-primary">Alterar</button>
            </td>
        </tr>
    </table>

</form>


<div id="yes" class="alert alert-success" style="display: none;">
  <strong>Pronto!</strong> Solicita&ccedil;&atilde;o efetuada com sucesso.
  <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
</div>

<div id="not" class="alert alert-danger" style="display: none;">
  <strong>Erro!</strong> N&atilde;o foi possivel efetivar a sua solicita&ccedil;&atilde;o.
  <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
</div>



</body>
</html>

where the action attribute is set to /blog/Usuario/altera/2 when it should be set to /blog/Usuario/altera .

Does anyone know how I can fix this?

    
asked by anonymous 21.06.2014 / 13:19

1 answer

0

Kleber,

Your problem is probably in the tag that generates the form, have you tried to add the parameter "action" and specify to "change"?

If you do not specify the action on the form, it uses a default value for the method on the called controller, in that case how the command comes from "change / 2" it uses it.

Hugs,

    
22.06.2014 / 20:00