2

我正在使用 Spring.AjaxEventDecoration 在我的 JSP 上动态填充下拉列表,但由于无法绑定到原始模型而引发错误。我已经对此进行了一段时间的研究,但我认为这是不可能的,但似乎应该是这篇文章..帮帮我吧!

好的,我的控制器哑了看起来像这样,

@Controller 
@RequestMapping(value = "/cis/crimeProperty/")
public class CrimePropertyController
{
  @RequestMapping(value = "/manageView", method = RequestMethod.GET)
  public ModelAndView managePropertyDetails(Long propertyId) throws DAOException
  {
    Map<String, Object> model = new HashMap<String, Object>();
    CrimePropertyVO crimePropertyVO = new CrimePropertyVO();
    model.put("crimePropertyVO", crimePropertyVO);
    return new ModelAndView("cis.crime.property.edit", model);
  }

  @RequestMapping(value = "/changeItemList", method = RequestMethod.POST)
  public ModelAndView retrieveItemList(String propertyClass)
  {
    Map<String, Object> model = new HashMap<String, Object>();
    ..call service to get list of items from class..
    model.put("propertyItemList", propertyItemList);
    return new ModelAndView("/cis/property/crime_property_item", model);
  }
}

我正在使用瓷砖,所以我的瓷砖定义看起来像这样,

<definition name="cis.crime.property.edit" template="/WEB-INF/jsp/cis/property/manage_crime_property.jsp">
<put-attribute name="itemListFrag" value="/WEB-INF/jsp/cis/property/crime_property_item.jsp"/>

我的 (manage_crime_property.jsp) JSP 看起来像这样,

<form id= "changeList" action="${pageContext.request.contextPath}/smvc/cis/crimeProperty/changeItemList" method="post">  
<select id="propertyClassChange" path="propertyClass">
  <option value="" label="-Please Select-"/>
  <option value="CLO" label="CLOTHING"/>
  <option value="TOL" label="TOOLS"/>
</select>
</form
<form:form modelAttribute="crimePropertyVO" action="${pageContext.request.contextPath}/smvc/cis/crimeProperty/saveProperty" method="post">
  <table class="genericOutlinedTable" style="width: 100%;">

<tr>
  <td><b>Item</b></td>
  <td>
    <tiles:insertAttribute name="itemListFrag" flush="true" ignore="false"/>
  </td>
</tr>

<tr>
  <td><b>Make</b></td>
  <td><form:input path="propertyMake" size="20" maxlength="20"/></td>
  <td><b>Model</b></td>
  <td><form:input path="propertyModel" size="15" maxlength="15"/></td>
</tr>
</form:form>     

<script type="text/javascript">

Spring.addDecoration(new Spring.AjaxEventDecoration({ elementId:'propertyClassChange', event:'onchange', formId:'changeList', params: {fragments: 'itemListFrag'} }));

My (crime_property_item.jsp) JSP fragment looks like this,

<span id="itemListFrag">
  <form:select path="propertyItem">
    <form:option value="" label="-Please Select-">
<c:forEach var="itemList" items="${propertyItemList}">
  <form:option value="${itemList.propertyCode}" label="${itemList.propertyCode}" />  
</c:forEach>  
  </form:select>
</span>

它全部配置正确,当我更改第一个下拉菜单时,它调用我的控制器 changeItemList 方法,该方法返回我的 JSP 片段和项目列表以组成选项,但我收到服务器错误...... BindingResult 和普通目标对象都不是 bean 名称propertyItemavailable 作为请求属性我尝试在我的 frag 中只使用选项标签,但这不起作用,我尝试使用 spring:bind 标签和正常选择,但也无法使其正常工作。

非常感谢您对此的任何帮助。

4

0 回答 0