Reputation: 2777
I have one JSP say myPage.jsp
in jsp I am havin two div
each div is containing one form as below:
div A:
<div class="validation-box">
<form:form id="compnay-detail" method="post" action="companySave.do" commandName="company">
<table cellpadding="0" cellspacing="0">
<tr>
<td class="col"><label>Address Type</label> <form:input type="text" path="addressType" class="textbox" name="addressType" id="addType" maxlength="20" />
</td>
<td class="col"><label>Street</label> <form:input path="street"
class="textbox" name="street" id="street" maxlength="50" />
</td>
</tr>
<tr>
<td colspan="3" class="no-padding">
<div class="button-pannel margin-top">
<span class="lhscrv"> <span class="rhscrv"> <input type="submit" class="bttn" id="saveAddress" value="Save" />
</span>
</span> <span class="lhscrv"> <span class="rhscrv"> <input
type="button" class="bttn" id="reset" value="Reset" />
</span>
</span> <span class="lhscrv"> <span class="rhscrv"> <input
type="button" class="bttn" id="cancel" value="Cancel" />
</span>
</span>
</td>
</tr>
</table>
</form:form>
</div>
div B:
<div class="validation-box">
<form:form id="compnayAddDetail" method="post" action="test.do" commandName="address">
<table cellpadding="0" cellspacing="0">
<tr>
<td class="col"><label>Address Type</label> <form:input type="text" path="addressType" class="textbox" name="addressType" id="addType" maxlength="20" />
</td>
<td class="col"><label>Street</label> <form:input path="street"
class="textbox" name="street" id="street" maxlength="50" />
</td>
</tr>
<tr>
<td colspan="3" class="no-padding">
<div class="button-pannel margin-top">
<span class="lhscrv"> <span class="rhscrv"> <input type="submit" class="bttn" id="saveAddress" value="Save" />
</span>
</span> <span class="lhscrv"> <span class="rhscrv"> <input
type="button" class="bttn" id="reset" value="Reset" />
</span>
</span> <span class="lhscrv"> <span class="rhscrv"> <input
type="button" class="bttn" id="cancel" value="Cancel" />
</span>
</span>
</td>
</tr>
</table>
</form:form>
</div>
MY CONTROLLER CLASS:
@RequestMapping("/companySave.do")
public String saveCompany(Map<String, Object> map, @ModelAttribute("company")
Company company,@ModelAttribute("address")
CompanyAddress address, BindingResult result)
{
//...... code.......
return "redirect:/companyAddressPage/"+company.getId()+".do";
}
@RequestMapping("/companyAddressPage/{id}.do")
public String companyAddressPage(@PathVariable("id") long id,Map<String, Object> map, @ModelAttribute("company")
Company company,@ModelAttribute("address")
CompanyAddress address, BindingResult result)
{ //...... code.......
return "myPage";
}
@RequestMapping("/test.do")
public String saveAddressCompany(Map<String, Object> map, @ModelAttribute("company")
Company company,@ModelAttribute("address")
CompanyAddress address, BindingResult result)
{ //...... code.......
return "myPage";
}
AIM:
after submitting first form which is present in div A i want to enable div B which will contain another form.
Problem :
First form is submitting properly but when i click on submit button of second form it is throwing exception (action is not even getting called)
Exception :
Unable to convert value test from type 'java.lang.String' to type 'long'; nested exception is java.lang.NumberFormatException: For input string: "test"] with root cause
any idea....???
Thanks in advance...!!!
Upvotes: 1
Views: 728
Reputation: 2975
EDIT: see comments also.
You need to add a forward slash in front of your second form's action attribute:
action="/test.do"
Otherwise you will end up to /companyAddressPage/test.do since you've just been redirected to /companyAddressPage/1.do (where 1 is an example id). This is because second form's action attribute is relative.
Upvotes: 1
Reputation: 4483
Whatever value you get in the @PathVariable it is always having String type value only.
So instead of using
@PathVariable("id") long id
use this
@PathVariable("id") String id
and then convert it to long manually before you use in your function.
Hope this helps you.
Cheers.
Upvotes: 0