submit - Spring 3 -- form with 2 buttons, sending 2 parameters to controller method -
i have spring 3 mvc form 2 parameters i'm trying send controller method, , i'm getting 404 error. twist on problem form has 2 submit buttons, , submit button clicked dictates value of 1 of parameters. here form.
<form:form action="/approve/${bulletin.id}" method="post"> <table> <tr> <td colspan="2"><b>from:</b> <c:out value="${bulletin.name}" /></td> </tr> <tr> <td colspan="2"><b>subject:</b> <c:out value="${bulletin.subject}" /></td> </tr> <tr> <td colspan="2"><b>date:</b> <c:out value="${bulletin.date}" /> <br></td> </tr> <tr> <td colspan="2"><t:noteprint note="${bulletin.note}" /> <input type="hidden" name="id" value="${bulletin.id}" /></td> </tr> <tr> <td><input type="submit" name="approve" value="approve" /></td> <td><input type="submit" name="deny" value="deny" /></td> </tr> </table> <br /> </form:form>
here controller form.
@requestmapping(value = "/approve/{id}", method = requestmethod.post) public string approvebulletin(@requestparam int id, @requestparam(required = false, value = "approve") string approve, @requestparam(required = false, value = "deny") string deny, model model) { try { if (approve.equalsignorecase("approve")) { bulletindao.approvebulletin(id); model.addattribute("approval", "your bulletin has been approved."); } if (deny.equalsignorecase("deny")) { bulletindao.denybulletin(id); model.addattribute("approval", "your bulletin has been denied."); } list<bulletin> bulletins = bulletindao.getapprovedbulletins(); model.addattribute("bulletins", bulletins); } catch (exception e) { system.out.println(e.getmessage()); return "failurepage"; } return "approvebulletin"; }
i have solved own problem. posting code benefit of else hits thread same problem. here form.
<form:form action="approve" method="post"> <table> <tr> <td colspan="2"><b>from:</b> <c:out value="${bulletin.name}" /></td> </tr> <tr> <td colspan="2"><b>subject:</b> <c:out value="${bulletin.subject}" /></td> </tr> <tr> <td colspan="2"><b>date:</b> <c:out value="${bulletin.date}" /> <br></td> </tr> <tr> <td colspan="2"><t:noteprint note="${bulletin.note}" /> <input type="hidden" name="id" value="${bulletin.id}" /></td> </tr> <tr> <td><input type="submit" name="approve" value="approve" /></td> <td><input type="submit" name="deny" value="deny" /></td> </tr> </table> <br /> </form:form>
here controller methods.
@requestmapping(value = "/approve", method = requestmethod.post, params = { "approve" }) public string approve(@requestparam int id, @requestparam string approve, model model) { try { bulletindao.approvebulletin(id); model.addattribute("approval", "your bulletin has been approved."); list<bulletin> bulletins = bulletindao.getapprovedbulletins(); model.addattribute("bulletins", bulletins); } catch (exception e) { system.out.println(e.getmessage()); return "failurepage"; } return "approvebulletin"; } @requestmapping(value = "/approve", method = requestmethod.post, params = { "deny" }) public string deny(@requestparam int id, @requestparam string deny, model model) { try { bulletindao.denybulletin(id); model.addattribute("approval", "your bulletin has been denied."); list<bulletin> bulletins = bulletindao.getapprovedbulletins(); model.addattribute("bulletins", bulletins); } catch (exception e) { system.out.println(e.getmessage()); return "failurepage"; } return "approvebulletin"; }
Comments
Post a Comment