2013-04-10 40 views
1

在下面的代码,我正确geeting列表和图,但是在更新我面临例如级联仅第一场rsoCode如果我的rsoCode是NH43然后它会涉及到控制器NH43,NH43。在更新的形式,它会显示正确,但是当它涉及到弹簧属性串联属性的值,随后由逗号

虽然调试我已经观察到,getRsoCode()调用的两倍,而即将更新屏幕(在这里我们可以更改值)。

这是JSP代码

<%@ 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">&nbsp;&nbsp;&nbsp;<input type="submit" value="Submit"/> </td> 
    </tr> 
    </table> 
    </form:form> 

控制器代码

@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; 
    } 


} 

回答

2

没有为你的形式不采取行动这将导致春季标签do weird stuff。 这:

<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" disabled="disabled"/></td> 
+0

上面我已经尝试过的解决方案但它仍然是行不通的。虽然调试运行我观察到,getRsoCode所谓的两倍,而redering更新的详细信息屏幕我指的是屏幕,一个可以改变 – Kamahire 2013-04-10 09:49:12

+0

在名单我已经看到在页面上查看源代码的数据值,它是填充在一次,但更新页它是填充两次,以及它如何添加逗号和连接这些值 – Kamahire 2013-04-10 09:57:54

+0

@Kamahire ListRsoDao返回什么?您需要将所有表单元素更改为仅引用路径。 – NimChimpsky 2013-04-10 10:03:27