0
I am using spring form tags to render the forms present in my views, but I am facing 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));
}
that will direct the application to this view:
private/<nome_da_classe>
/altera.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/altera.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 html is being rendered for 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ção efetuada com sucesso.
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
</div>
<div id="not" class="alert alert-danger" style="display: none;">
<strong>Erro!</strong> Não foi possivel efetivar a sua solicitação.
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
</div>
</body>
</html>
where the action attribute is with the value /blog/Usuario/altera/2
when it should be just /blog/Usuario/altera
.
someone knows how I can fix this?
I managed to solve here: it was to use
action=${param.altera}
and I had usedaction=${altera}
– user7414