Hi all I am using spring mvc and I have a form where I have to use a combo box in step a list of objects driver to be loaded into the combo box but it turns out I show it as a string and not as the object .
a little above I have a combo box where I pass in the same way but is out of form and position with JSTL.
what I need is that the first two attributes of my object is loaded for the combo box
Here is the code and images so they can help me.
Controller
#RequestMapping(value="products.htm", method=RequestMethod.GET)
public String homeSuppliers(#RequestParam(required=false) String state, ModelMap model){
try {
if (state != null) {
model.addAttribute("state", state);
}
List<ProveedoresDTO> listSupplier = supplierService.getAllSuppliersDTO();
List<ProductosDTO> listProducts = productService.getAllProductsDTO();
model.addAttribute("listProducts",listProducts);
model.addAttribute("listSupplier",listSupplier);
model.addAttribute("productAtt", new ProductsDTO());
} catch (Exception e) {
model.addAttribute("msg",e.getMessage());
}
return "productsView/products";
}
JSP
<select id="comboProducts" onchange="BuscaProductPorId()">
<option value="0"></option>
<c:forEach items="${listProducts}" var="product">
<option value="${product.productID}">${product.productName}</option>
</c:forEach>
</select>
<h1>${msg}</h1>
<form:form commandName="productAtt" action="crearProduct" method="get"
id="formSend">
<fieldset>
<legend>Product</legend>
<form:hidden path="productID" />
<table>
<tr>
<td><form:label path="productName">Nombre Product</form:label></td>
<td>:</td>
<td><form:input path="productName" /></td>
<td><form:errors path="productName" /></td>
</tr>
<tr>
<td><form:label path="supplierID">Select Supplier</form:label></td>
<td>:</td>
<td><form:select path="supplierID" multiple="false" items="${listSupplier}"></form:select></td>
<td><form:errors path="supplierID" /></td>
</tr>
<tr>
<td><form:label path="quantityPerUnit">Cantidad por Unidad</form:label></td>
<td>:</td>
<td><form:input path="quantityPerUnit" /></td>
<td><form:errors path="quantityPerUnit" /></td>
</tr>
<tr>
<td><form:label path="unitPrice">Precio Unitario</form:label></td>
<td>:</td>
<td><form:input path="unitPrice" /></td>
<td><form:errors path="unitPrice" /></td>
</tr>
<tr>
<td><form:label path="unitsInStock">Unidades en Stock</form:label></td>
<td>:</td>
<td><form:input path="unitsInStock" /></td>
<td><form:errors path="unitsInStock" /></td>
</tr>
<tr>
<td><form:label path="unitsOnOrder">Unidades en Orden</form:label></td>
<td>:</td>
<td><form:input path="unitsOnOrder" /></td>
<td><form:errors path="unitsOnOrder" /></td>
</tr>
<tr>
<td><form:label path="reorderLevel">Nivel de Orden</form:label></td>
<td>:</td>
<td><form:input path="reorderLevel" /></td>
<td><form:errors path="reorderLevel" /></td>
</tr>
<tr>
<td><form:label path="discontinued">Descontinuado</form:label></td>
<td>:</td>
<td><form:input path="discontinued" /></td>
<td><form:errors path="discontinued" /></td>
</tr>
<tr>
<td><br></td>
</tr>
<tr>
<td><input type="submit" value="Crear Product" name="crea"
id="crea"></td>
<td><input type="button" onclick="formReset()"
value="Limpiar Campos" /></td>
</tr>
</table>
</fieldset>
</form:form>
Result
You are not specifying what to use for your options. Try this:
<form:select path="supplierID" multiple="false">
<form:options items="${listSupplier}" itemValue="SupplierID" itemLabel="CompanyName"/>
</form:select>
Please note the items name has been changed to match the one given by the #Controller
Related
this is my jsp file to edit data.
CustomerEdit.jsp
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Edit</title>
</head>
<body>
<div align="center">
<h3>Edit Customer Information</h3>
</div>
<form:form id="editForm" modelAttribute="user" action="editsave"
method="post">
<table align="center">
<tr>
<td><form:label path="customerid"></form:label></td>
<td><form:hidden path="customerid" name="customerid" id="customerid" /></td>
</tr>
<tr>
<td><form:label path="firstname">Firstname</form:label></td>
<td><form:input path="firstname" name="firstname" id="firstname" /></td>
</tr>
<tr>
<td><form:label path="lastname">Lastname</form:label></td>
<td><form:input path="lastname" name="lastname" id="lastname" /></td>
</tr>
<tr>
<td><form:label path="street">Street</form:label></td>
<td><form:input path="street" name="street" id="street" /></td>
</tr>
<tr>
<td><form:label path="city">City</form:label></td>
<td><form:input path="city" name="city" id="city" /></td>
</tr>
<tr>
<td><form:label path="province">Province</form:label></td>
<td><form:input path="province" name="province" id="province" /></td>
</tr>
<tr>
<td><form:label path="country">Country</form:label></td>
<td><form:input path="country" name="country" id="country" /></td>
</tr>
<tr>
<td><form:label path="birthday">Birthday</form:label></td>
<td><form:input path="birthday" name="birthday" id="birthday" /></td>
</tr>
<tr>
<td><form:label path="sin">SIN</form:label></td>
<td><form:input path="sin" name="sin" id="sin" /></td>
</tr>
<tr>
<td><form:label path="passport">Passport Number</form:label></td>
<td><form:input path="passport" name="passport" id="passport" /></td>
</tr>
<tr>
<td><form:label path="nationality">Nationality</form:label></td>
<td><form:input path="nationality" name="nationality" id="nationality" /></td>
</tr>
<tr>
<td><form:label path="email">Email Address</form:label></td>
<td><form:input path="email" name="email" id="email" /></td>
</tr>
<tr>
<td><form:label path="loginid"></form:label></td>
<td><form:hidden path="loginid" name="loginid" id="loginid" /></td>
</tr>
<tr>
<td><form:label path="password">Password</form:label></td>
<td><form:password path="password" name="password"
id="password" /></td>
</tr>
<tr>
<td></td>
<td><form:button id="submit" name="submit">Save</form:button></td>
</tr>
</table>
</form:form>
</body>
</html>
and my controller
#Controller
public class RegisterControl {
#Autowired
UserDao dao;
#RequestMapping(value = "/editcust/{customerid}")
public ModelAndView edit(#PathVariable int customerid, Model m) {
User cust = dao.getCustomerById(customerid);
ModelAndView mav = new ModelAndView("CustomerEdit");
mav.addObject("user", cust);
return mav;
}
public UserService userService;
#RequestMapping(value = "/editsave", method = RequestMethod.POST)
public String editsave(#ModelAttribute("user") User user) {
System.out.println("HELLOOOOO!!!!!");
dao.update(user);
return "redirect:/homepage";
}
}
I get My customerEdit form with data. but when I click on save to update my data I get Exception
Failed to convert value of type 'java.lang.String' to required type 'int'; nested exception is java.lang.NumberFormatException: For input string: "editsave"]
I don't even get HELLOOOO printed on console.
PS: My Register form is working but getting error while updating data.
Please Help. Thanks in advance.
Apparently you are sending some kind of User field which is declared as int equal to "editsave" (which is string).
You can just change all User fields to String and check (with debug) which field is making problems.
You should realy make sure that client isn't able to send non number type of that field, although it may be tricky because you can't add type attribute because the spring:input form tag doesnt support the type attribute and there is no such thing as spring:number. But you can use jquery to add the type="number" attribute to the parsed html. Something like this:
$(".selector").attr({
"type" : "number",
});
EDIT after new exception:
you also need to add BindingResult to your controller method. In case you want to validate any field of User object you can set errors into it. If not, you can just copy my snippet
public UserService userService;
#RequestMapping(value = "/editsave", method = RequestMethod.POST)
public String editsave(#ModelAttribute("user") User user, BindingResult result) {
System.out.println("HELLOOOOO!!!!!");
dao.update(user);
return "redirect:/homepage";
}
I'm trying to create an edit form and prepopulate to form with the chosen objects values but it is returning an HTTP status of 404 and the error message I'm getting is
org.springframework.web.servlet.DispatcherServlet.noHandlerFound No
mapping for GET
/AgentsCRUD/agent/edit/1;jsessionid=07E2EC08848D0C9C9346DC67563DDF1F
I think what I have is pretty logical but I must have messed up with the mapping.
The code in the get AllAgent.jsp
<spring:message code="welcome.message" />
<body>
<table style="width:100%">
<tr>
<th align="left"><spring:message code="label.agentId" /></th>
<th align="left"><spring:message code="label.name" /></th>
<th align="left"><spring:message code="label.fax" /></th>
<th align="left"><spring:message code="label.phone" /></th>
<th align="left"><spring:message code="label.email" /></th>
<th align="left"><spring:message code="label.datejoined" /></th>
<th align="left"><spring:message code="label.sales" /></th>
<th align="left"><spring:message code="label.actions" /></th>
</tr>
<c:forEach items="${agentList}" var="agent">
<tr>
<td>${agent.agentId}</td>
<td>${agent.name}</td>
<td>${agent.fax}</td>
<td>${agent.phone}</td>
<td>${agent.email}</td>
<td>
<spring:message code="label.delete" />
<spring:url value="/agent/edit/${agent.agentId}" var="editURL"/>
<spring:message code="label.edit" />
<spring:message code="label.insert" />
</td>
</tr>
</c:forEach>
</table>
</body>
the code in the controller AgentController.java
#GetMapping("/edit")
public ModelAndView EditAnAgent(#QueryParam("agentId") int agentId) {
return new ModelAndView("/editAgent", "agent", service.getAgentById(agentId));
}
#GetMapping("/editAgent")
public ModelAndView editAgent(#Valid #ModelAttribute("agent") Agents a, BindingResult result, ModelMap model) {
if (result.hasErrors()) {
return new ModelAndView("/editAgent");
}
service.editAgent(a);
return new ModelAndView("redirect:/agent");
}
the code in the Model AgentService.java
public static Agents getAgentByID(int agentId) {
EntityManager em = DBUtil.getEMF().createEntityManager();
Agents a = null;
try {
a = em.createNamedQuery("Agents.findByAgentId", Agents.class)
.setParameter("agentId", (agentId))
.getSingleResult();
} catch (Exception ex) {
System.out.println("Error in getting property details: " + ex);
} finally {
em.clear();
}
return a;
}
public void editAgent(Agents a) {
EntityManager em = DBUtil.getEMF().createEntityManager();
EntityTransaction transaction = em.getTransaction();
try {
transaction.begin();
em.merge(a);
transaction.commit();
} catch (Exception e) {
System.out.println(e);
} finally {
em.close();
}
}
the code in the editAgent.jsp
<form:form method="POST" action="/AgentsCRUD/agent/editAgent" modelAttribute="agent">
<table>
<tr>
<td><form:label path="agentId"><spring:message code="label.agentId" /></form:label></td>
<td><form:input path="agentId"/></td>
<td style="color:red"><form:errors path="agentId"/> </td>
</tr>
<tr>
<td><form:label path="name"><spring:message code="label.name" /></form:label></td>
<td><form:input path="name" /></td>
<td style="color:red"><form:errors path="name"/> </td>
</tr>
<tr>
<td><form:label path="phone"><spring:message code="label.phone" /></form:label></td>
<td><form:input path="phone"/></td>
<td style="color:red"><form:errors path="phone"/> </td>
</tr>
<tr>
<td><form:label path="fax"><spring:message code="label.fax" /></form:label></td>
<td><form:input path="fax"/></td>
<td style="color:red"> <form:errors path="fax"/> </td>
</tr>
<tr>
<td><form:label path="email"><spring:message code="label.email" /></form:label></td>
<td><form:input path="email"/></td>
<td style="color:red"> <form:errors path="email"/> </td>
</tr>
<tr>
<td><form:label path="username"><spring:message code="label.username" /></form:label></td>
<td><form:input path="username"/></td>
<td style="color:red"> <form:errors path="username"/> </td>
</tr>
<tr>
<td><form:label path="password"><spring:message code="label.password" /></form:label></td>
<td><form:input path="password"/></td>
<td style="color:red"> <form:errors path="password"/> </td>
</tr>
<tr>
<spring:message code="submit.button" var="labelSubmit"></spring:message>
<td><input type="submit" value="${labelSubmit}"/></td>
</tr>
</table>
</body>
</form:form>
In the Error the url given is .../edit/1 where 1 is a path parameter,
However in the get mapping, you are trying to read it as a query parameter.
Try this.
#GetMapping("/edit/{agentId}")
Patient getEmployee(#PathParam("agentId") int agentId) ;
<form:form action="saveNewUsers" method="post" modelAttribute="users">
<table>
<tr><td>Id</td>
<td><form:input path="id"/></td>
</tr>
<tr>
<td>User</td>
<td><form:input path="user" /></td>
</tr>
<tr>
<td>Password</td>
<td><form:input path="password" /></td>
</tr>
<tr>
<td>FirstName</td>
<td><form:input path="first_name" /></td>
</tr>
<tr>
<td>LastName</td>
<td><form:input path="last_name" /></td>
</tr>
<tr>
<td>Group Id</td>
<td>
<select name="GroupId">
<c:forEach items="${users.al}" var="item">
<option value="${item.value}">${item.value}</option>
</c:forEach>
</select>
</td>
<tr>
<td colspan="2" align="center"><input type="submit" value="Save"></td>
</tr>
</table>
Please let me know how to get ArrayList attribute from ModelObject of 'users' and print those values of ArrayList as DROPDOWN Menu in JSP.
Actually I send that 'users' model object from the Controller of the Spring MVC
I'm using Struts2 and This is my form in JSP
<s:form target="_top" cssClass="table-controls form-wrapper" name="incentives" id="frmIncentives" action="saveIncentives.action" method="post">
<div id="actionErrors" style="color: red;">
<s:actionerror />
<s:fielderror />
</div>
<table id ="showIncentives" cellspacing="0" cellpadding="0" border="1" width="500" >
<tr style="font-weight: bold">
<td><s:checkbox name="Select All" id="select_all"
theme="simple" /></td>
<td>
<td></td>
<td></td>
<td><s:text name="Marketing Incentive" /></td>
<td></td>
<td><s:text name="Advertising Incentive" /></td>
<td></td>
<td><s:text name="Channel Placement Incentive" /></td>
<td></td>
</tr>
<s:iterator value="incentiveList" status="stat">
<tr>
<td><s:checkbox name="checkboxes[%{#stat.index}]" theme="simple" /></td>
<td></td>
<td><s:property value="pricingTierId" /> <s:hidden value="%{incentiveList.pricingTierId}" /></td>
<td><s:property value="marketingAmount" /> <s:hidden value="%{incentiveList.marketingAmount}" /></td>
<td></td>
<td><s:property value="marketingIncentive" /></td>
<td></td>
<td><s:property value="advertizingIncentive" /></td>
<td></td>
<td><s:property value="channelPlacementIncentive" /></td>
<td></td>
</tr>
</s:iterator>
</table>
<c:if test="${fn:length(incentiveList) == 0}">
<s:submit id="submitButton" name="submit" value="Submit Incentives" onclick='return closeWindow()' disabled="true"/>
</c:if>
<c:if test="${fn:length(incentiveList) gt 0}">
<s:submit id="submitButton" name="submit" value="Submit Incentives" onclick='return closeWindow()' disabled="false"/>
</c:if>
</s:form>
And now method in my Action class is as below
private String marketingIncentive;
private String advertizingIncentive;
private String channelPlacementIncentive;
private BigDecimal marketingAmount;
private Integer pricingTierId;
//getters and setters
public String getMarketingIncentive() {
return marketingIncentive;
}
public void setMarketingIncentive(String marketingIncentive) {
this.marketingIncentive = marketingIncentive;
}
public String getAdvertizingIncentive() {
return advertizingIncentive;
}
public void setAdvertizingIncentive(String advertizingIncentive) {
this.advertizingIncentive = advertizingIncentive;
}
public String getChannelPlacementIncentive() {
return channelPlacementIncentive;
}
public void setChannelPlacementIncentive(String channelPlacementIncentive) {
this.channelPlacementIncentive = channelPlacementIncentive;
}
public BigDecimal getMarketingAmount() {
return marketingAmount;
}
public void setMarketingAmount(BigDecimal marketingAmount) {
this.marketingAmount = marketingAmount;
}
// Method to save the selected checkbox values
public String saveIncentives(){
WorkFlowDAO workFlowDAO = new WorkFlowDAO();
try {
if(submit != null){
IncentiveDetailsDO incentiveDetailsDO = new IncentiveDetailsDO();
incentiveDetailsDO.setPricingTierId(pricingTierId);
incentiveDetailsDO.setMarketingAmount(marketingAmount);
incentiveDetailsDO.setMarketingIncentive(marketingIncentive);
incentiveDetailsDO.setAdvertizingIncentive(advertizingIncentive);
incentiveDetailsDO.setChannelPlacementIncentive(channelPlacementIncentive);
workFlowDAO.applyIncentives(incentiveDetailsDO);
closeWindow = true;
}
} catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}
The
pricingTierId , marketingIncentive, advertizingIncentive ,
channelPlacementIncentive and channelPlacementIncentive
are passed to the function as null in spite of having getters and setters in the Action class .
I have made the changes as suggested below
<s:iterator value="incentiveList" status="stat">
<tr>
<td><s:checkbox name="checkboxes[%{#stat.index}]" theme="simple" /></td>
<td></td>
<td><s:property value="pricingTierId" /> <s:hidden name="pricingTierId" value="%{incentiveList.pricingTierId}" /></td>
<td><s:property value="marketingAmount" /> <s:hidden name="marketingAmount" value="%{incentiveList.marketingAmount}" /></td>
<td></td>
<td><s:property value="marketingIncentive" />
<s:hidden name="marketingIncentive" value="%{incentiveList.pricingTierId}" />
</td>
<td></td>
<td><s:property value="advertizingIncentive"/>
<s:hidden name="advertizingIncentive" value="%{incentiveList.pricingTierId}"/>
</td>
<td><s:property value="channelPlacementIncentive" />
<s:hidden name="channelPlacementIncentive" value="%{incentiveList.pricingTierId}" />
</td>
<td></td>
</tr>
</s:iterator>
Still all the values are being passed as null .
Please suggest
Your form will be look like this .
<s:form target="_top" cssClass="table-controls form-wrapper" name="incentives" id="frmIncentives" action="saveIncentives.action" method="post">
<div id="actionErrors" style="color: red;">
<s:actionerror />
<s:fielderror />
</div>
<table id ="showIncentives" cellspacing="0" cellpadding="0" border="1" width="500" >
<tr style="font-weight: bold">
<td><s:checkbox name="Select All" id="select_all"
theme="simple" /></td>
<td>
<td></td>
<td></td>
<td><s:text name="Marketing Incentive" /></td>
<td></td>
<td><s:text name="Advertising Incentive" /></td>
<td></td>
<td><s:text name="Channel Placement Incentive" /></td>
<td></td>
</tr>
<s:iterator value="incentiveList" status="stat">
<tr>
<td><s:checkbox name="checkboxes[%{#stat.index}]" theme="simple" /></td>
<td></td>
<td><s:property value="pricingTierId" /> <s:hidden name="pricingTierId" value="%{incentiveList.pricingTierId}" /></td>
<td><s:property value="marketingAmount" /> <s:hidden name="marketingAmount" value="%{incentiveList.marketingAmount}" /></td>
<td></td>
<td><s:property value="marketingIncentive" /><s:hidden name="marketingIncentive" value="%{incentiveList.marketingIncentive}" /></td>
<td></td>
<td><s:property value="advertizingIncentive" /><s:hidden name="advertizingIncentive" value="%{incentiveList.advertizingIncentive}" /></td>
<td></td>
<td><s:property value="channelPlacementIncentive" /><s:hidden name="channelPlacementIncentive" value="%{incentiveList.channelPlacementIncentive}" /></td>
<td></td>
</tr>
</s:iterator>
</table>
<c:if test="${fn:length(incentiveList) == 0}">
<s:submit id="submitButton" name="submit" value="Submit Incentives" onclick='return closeWindow()' disabled="true"/>
</c:if>
<c:if test="${fn:length(incentiveList) gt 0}">
<s:submit id="submitButton" name="submit" value="Submit Incentives" onclick='return closeWindow()' disabled="false"/>
</c:if>
</s:form>
i have a JSP with hyperlink
<table>
<tr>
<td>Product Name : </td>
<td>${product.name}</td>
</tr>
<tr>
<td>Description:</td>
<td>${product.description}</td>
</tr>
<tr>
<td>Price:</td>
<td>${product.price}</td>
</tr>
<tr><td> </td></tr>
<tr>
<td>
Add to shopping basket
</td>
</tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr>
<td>
<table>
<tr>
<td>Return to Home Page</td>
<td> </td>
<td>Logout
(<security:authentication property="principal.username" />)
</td>
</tr>
</table>
</td>
</tr>
And the controller
#Controller
#SessionAttributes("basket")
public class ShopBasketController {
private BasketManager basketManager;
private CustomerManager customerManager;
private CategoryManager categoryManager;
#Autowired
public ShopBasketController(BasketManager basketManager, CustomerManager customerManager, CategoryManager categoryManager) {
this.basketManager = basketManager;
this.customerManager = customerManager;
this.categoryManager = categoryManager;
}
#RequestMapping(value="/basketItems", method=RequestMethod.POST)
public String removeProduct(#ModelAttribute("basket") Basket basket, BindingResult bindingResult, Model model) {
Basket newBasket = ShoppingBasketUtils.removeFromBasket(basket, basketManager);
basketManager.update(newBasket);
model.addAttribute("basket",newBasket);
model.addAttribute("customer", "Sonx"+" Nkuks");
model.addAttribute("totalItems", basketManager.getTotalNumberOfItems(basket));
model.addAttribute("totalPrice", ShoppingBasketUtils.currencyFormat(basketManager.getTotalProductPrice(basket)));
return "basketItems";
}
#RequestMapping("/populateBasket")
public String populateBasket(#RequestParam("code") String productCode, #RequestParam("name") String categoryName, Model model) {
Customer customer = customerManager.getCustomer("Sonx", "Nkuks");
if(customer != null) {
Basket shopBasket = ShoppingBasketUtils.addToBasket(productCode, categoryManager.getCategory(categoryName),
basketManager.getBasket(customer.getReferenceNumber()), basketManager);
basketManager.update(shopBasket);
model.addAttribute("basket",shopBasket);
model.addAttribute("customer", customer.getFirstName()+" "+customer.getLastName());
model.addAttribute("totalItems", basketManager.getTotalNumberOfItems(shopBasket));
model.addAttribute("totalPrice", ShoppingBasketUtils.currencyFormat(basketManager.getTotalProductPrice(shopBasket)));
return "basketItems";
}
model.addAttribute("customer", "test".concat(" test"));
return "/error";
}
}
Then the form ...
<form:form commandName="basket">
<table>
<tr>
<td>
<table>
<tr>
<td>Customer Name : </td>
<td>${customer}</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="600" border="1" cellspacing="0" cellpadding="2"
border="0">
<thead>
<tr>
<td>Products:</td>
</tr>
<tr>
<td>Product Name</td>
<td>Product Code</td>
<td>Description</td>
<td>Price</td>
<td>Remove</td>
</tr>
</thead>
<tbody>
<c:forEach items="${basket.products}" var="product">
<tr>
<td>${product.name}</td>
<td>${product.productCode}</td>
<td>${product.description}</td>
<td>${product.price}</td>
<td><form:checkbox path="removeItemCodes" value="${product.productCode}" /></td>
</tr>
</c:forEach>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>Total Price</td>
<td> </td>
<td>${totalPrice}</td>
</tr>
<tr>
<td>Total Items</td>
<td> </td>
<td>${totalItems}</td>
</tr>
</table>
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td><input type="submit" value="Remove Items" /></td>
</tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr>
<td>
<table>
<tr>
<td>Return to Home Page</td>
<td> </td>
<td>Logout
(<security:authentication property="principal.username" />)
</td>
</tr>
</table>
</td>
</tr>
</table>
When i press the link from the first JSP "" the controller succesfully execute the method populateBasket and loads the Form. But when i submit the form, i want it to call the POST method (basketItems)... But it doesn't, pressng the submit button always executes the GET method (populateBasket) .. This doesn't happen if i load the form directly from the index page, it loads successfully . Problem is when coming from that JSP ?
If you want the form to submit to a different URL from the one that was used to retrieve the page, you need to explicitly set the action on it. Otherwise Spring is going to just fill it in with the current URL.