Reputation: 2209
In below code, I am geeting list and view correctly but while updating I am facing only first field rsoCode concatenated e.g. if my rsoCode is NH43 then it will comes to controller as NH43,NH43. In the update form it displays correctly but when it comes to
While debug I have observed that the getRsoCode() invoked twice while coming to update screen(where we can change the values).
This is JSP code
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<form:form action="" method="POST" commandName="updateRso">
<table>
<tr>
<td style="font-weight: bold; font-variant: small-caps;">RSO Code:</td>
<td><form:input path="rsoCode" value="${updateRso.rsoCode}" disabled="disabled"/></td></tr>
<tr><td style="font-weight: bold; font-variant: small-caps;">RSO Description:</td>
<td><form:input path="rsoDescriprion" value="${updateRso.rsoDescriprion}"/></td>
</tr>
<tr>
<td style="font-weight: bold; font-variant: small-caps;">Region Code:</td>
<td><form:input path="regionCode" value="${updateRso.regionCode}"/></td></tr>
<tr><td style="font-weight: bold; font-variant: small-caps;">Region Description:</td>
<td><form:input path="regiondescription" value="${updateRso.regiondescription}"/></td>
</tr>
<tr>
<td colspan="10" align="center"> <input type="submit" value="Submit"/> </td>
</tr>
</table>
</form:form>
Controller Code
@Controller
public class ListRsoController {
private static final Logger logger = LoggerFactory.getLogger(ListRsoController.class);
@ModelAttribute("updateRso")
public ListRso getListRso()
{
ListRso updateRso = new ListRso();
return updateRso;
}
@RequestMapping(value="listrso")
public String listAllRso(ModelMap model) throws Exception{
ListRsoDao listDao = new ListRsoDao();
model.addAttribute("rsos", listDao.getList());
return "listrso/view";
}
@RequestMapping(value="getRsoDetails")
public String getRso(@RequestParam("rsoCode")String rsoCode, ModelMap model,HttpServletRequest req) throws Exception{
ListRsoDao lstdto = new ListRsoDao();
Object obj = lstdto.getRsoCode(rsoCode);
model.addAttribute("savedClass", obj);
return "listrso/viewdetails";
}
@RequestMapping(value="updateRsoDetails", method=RequestMethod.GET)
public String updateRso(@RequestParam("rsoCode")String rsoCode, ModelMap model,HttpServletRequest req) throws Exception{
ListRsoDao lstdto = new ListRsoDao();
Object obj = lstdto.getRsoCode(rsoCode);
model.addAttribute("updateRso", obj);
return "listrso/updatedetails";
}
@RequestMapping(value="deleteRsoDetails")
public String deleteRso(@RequestParam("rsoCode")ListRso rsoCode, ModelMap model,HttpServletRequest req) throws Exception{
ListRsoDao lstdto = new ListRsoDao();
lstdto.deleteRso(rsoCode);
//model.addAttribute("savedClass", obj);
return "listrso/deleteSuccess";
}
@RequestMapping(method = RequestMethod.POST, value="updateRsoDetails")
protected String onSubmit( @ModelAttribute("updateRso") ListRso rsoCommand, ModelMap model ) throws Exception
{
model.clear();
new ListRsoDao().updateRso(rsoCommand);
model.addAttribute("savedClass", rsoCommand);
return "listrso/view";
}
}
Java Bean
public class ListRso {
private String rsoCode;
private String rsoDescriprion;
private String regionCode;
private String regiondescription;
public ListRso(String rsoCode, String rsoDescriprion, String regionCode,
String regiondescription) {
super();
this.rsoCode = rsoCode;
this.rsoDescriprion = rsoDescriprion;
this.regionCode = regionCode;
this.regiondescription = regiondescription;
}
public ListRso(String rsoCode)
{
this.rsoCode = rsoCode;
}
public ListRso() {
// TODO Auto-generated constructor stub
}
public String getRsoCode() {
return rsoCode;
}
public void setRsoCode(String rsoCode) {
this.rsoCode = rsoCode;
}
public String getRsoDescriprion() {
return rsoDescriprion;
}
public void setRsoDescriprion(String rsoDescriprion) {
this.rsoDescriprion = rsoDescriprion;
}
public String getRegionCode() {
return regionCode;
}
public void setRegionCode(String regionCode) {
this.regionCode = regionCode;
}
public String getRegiondescription() {
return regiondescription;
}
public void setRegiondescription(String regiondescription) {
this.regiondescription = regiondescription;
}
}
Upvotes: 2
Views: 2616
Reputation: 1
Recently I have came across similar issue Root cause of the issue was that I have defined same path variable twice one visible on the screen and the other one was hidden. While submitting the form it was concatinating value with same path/name by commqnd. To fix this you have remove the hidden one.
Hope this information helps
Upvotes: 0
Reputation: 47290
There is no action for your form this causes spring tags to do weird stuff. And this :
<form:form action="" method="POST" commandName="updateRso">
means you only need to do this (remove the value attribute, the input is populated from path)
<table>
<tr>
<td style="font-weight: bold; font-variant: small-caps;">RSO Code:</td>
<td><form:input path="rsoCode" disabled="disabled"/></td>
Upvotes: 3