I am new to spring and I am facing the following issue:
Edited Description:
I was able to make a POST call by making a new controller and ModelAndView method but now I am facing one more problem of data not getting passed from JSP to controller. My JSP code is:
form:form method="POST" action="UserOperation"
modelAttribute="DebitModel">
<h3>Debit</h3>
<c:if test="${!empty listAccounts}">
<select name="item" id="account_dropdown"
onchange="changeAccountDetails(this.options[this.selectedIndex].value)">
<c:forEach items="${listAccounts}" var="account">
<option
value="${account.accID},${account.acctype},${account.balance}">AccID:
${account.accID} Balance: ${account.balance}</option>
</c:forEach>
</select>
<br>
<br>
<label ><b>Account ID: </b></label>
<label id="accIdText" path="accID">${listAccounts[0].accID}</label>
<label><b>Account Type: </b></label>
<label id="accTypeText" path="acctype">${listAccounts[0].acctype}</label>
<label><b>Balance: </b></label>
<label id="accBalText" path="balance">${listAccounts[0].balance}</label>
</c:if>
<br> <br> Enter Amount<input type="text"
id="amount" width="80" path="amount"></input> <br> <br>
<input type="submit" value="Debit"></input>
</form:form>
There is a normal bean class named DebitModel. I tried to search and at many places for the data not getting passed and found solution as form:input mentioned but if I use this I get no Binding FoundException 'java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'DebitModel' available as request attribute ' even if <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%> is present.
The Controller class Code:
@Controller
@RequestMapping(value = "/UserOperation")
public class DebitController {
@Autowired
private AccountService mAccountService;
@RequestMapping(method = RequestMethod.POST)
public ModelAndView registerCustomer(@ModelAttribute("DebitModel") DebitModel debitModel, BindingResult result,
HttpServletRequest request) throws NoSuchAlgorithmException, FileNotFoundException {
ModelAndView modelAndView = new ModelAndView();
System.out.println("data------------------------" + debitModel.toString());
return modelAndView;
}
}