我正在尝试在下面做。在我的 JSP 中,我创建了一个表,其标题为“2013 年 10 月”、“2013 年 11 月”、....等未来 12 个月。即直到“2014 年 9 月”。
这些月份和年份应该是最新的,例如,如果月份是 2013 年 11 月,那么系统应该检测到 2013 年 11 月,并且应该增加 12 个月,直到明年 2014 年 10 月。
有 12 个输入字段(每个月一个),它们在一行中。用户可以在此表中动态添加新行,并可以在这些文本字段中输入月份的任何输入字段的数量值。
<table border="1" class="atable" align="center" width="85%">
<tr>
<th>LRN Required</th>
<th>Oct 2013</th>
<th>Nov 2013</th>
<th>Dec 2013</th>
<th>Jan 2014</th>
<th>Feb 2014</th>
<th>Mar 2014</th>
<th>Apr 2014</th>
<th>May 2014</th>
<th>June 2014</th>
<th>Jul 2014</th>
<th>Aug 2014</th>
<th>Sept 2014</th>
</tr>
<tr>
<td></td>
<td><input type="text" size="4"/></td>
<td><input type="text" size="4"/></td>
<td><input type="text" size="4"/></td>
<td><input type="text" size="4"/></td>
<td><input type="text" size="4"/></td>
<td><input type="text" size="4"/></td>
<td><input type="text" size="4"/></td>
<td><input type="text" size="4"/></td>
<td><input type="text" size="4"/></td>
<td><input type="text" size="4"/></td>
<td><input type="text" size="4"/></td>
<td><input type="text" size="4"/></td>
</tr>
</table>
我正在使用 Spring MVC,并希望将 JSTL 用于此功能。
型号类:
public class Forecast {
private int id;
private int quantity;
private String lastUpdatedBy;
private String rateCenter;
.....
getters and setters here...
}
My controller class looks like below...
@Controller
@SessionAttributes("forecastModel")
public class ForecastController extends PasBaseController {
@Autowired
HttpServletRequest request;
protected static Logger log = Logger.getLogger(ForecastController.class);
private static final String FRCST_MODEL = "forecastModel";
@RequestMapping(value="preforecast.do")
public String setUpPreforecast(final Model model, HttpServletRequest req)
{
User user = WebUtil.getSignInUser(req);
ForecastModel forecastModel = new ForecastModel();
log.debug("User Info.");
log.debug(user.getUserId());
log.debug(user.getFullName());
log.debug(user.getPhone());
Long id = (long) 15260;
List<Long> userNpaList = null;
List<String> userOcnList = null;
try{
if(user != null)
{
userNpaList = PasServicesUtils.getAllNpaAssocForUserId(id);
userOcnList = PasServicesUtils.geAllOcnAssocForUserId(id);
model.addAttribute("userNpaList", userNpaList);
model.addAttribute("userOcnList", userOcnList);
forecastModel.setUserNpaList(userNpaList);
forecastModel.setUserOcnList(userOcnList);
model.addAttribute("forecastModel", forecastModel);
}
}catch(Exception e){
log.error("List is NULL");
}
log.debug("Exiting setUpPreforecast() method.");
return PasConstants.PREFORECAST;
}
@RequestMapping(value = {PasConstants.FORECAST})
public String continueFromPreforecast(@ModelAttribute("forecastModel") ForecastModel forecastModel, Errors errors, HttpServletRequest request, final ModelMap modelMap) throws Exception
{
User user = WebUtil.getSignInUser(request);
modelMap.addAttribute("ocn", forecastModel.getOcn());
modelMap.addAttribute("phone", user.getPhone());
modelMap.addAttribute("fax", user.getFax());
modelMap.addAttribute("email", user.getEmail());
modelMap.addAttribute("forecastRptDt", PasDate.displayDayMonthYearFormat2(new PasDate()));
modelMap.addAttribute("npa", forecastModel.getNpa());
List<String> rateCntrAbbrList;
rateCntrAbbrList = PasServicesUtils.getAllRtCntrsAssocForNpa(forecastModel.getNpa());
if(rateCntrAbbrList != null && rateCntrAbbrList.size() > 0)
{
modelMap.addAttribute("rateCntrAbbrList", rateCntrAbbrList);
}
//modelMap.addAttribute("rateCtr", forecastModel.getRtCntrId().
//validateForecastData(forecastModel, errors, user);
if (errors.hasErrors())
{
return PasConstants.PREFORECAST;
}
return PasConstants.FORECAST;
}
@RequestMapping(value = {PasConstants.FORECAST_SUCCESS}, method = RequestMethod.POST)
public String submitForecast(@ModelAttribute("forecastModel") ForecastModel forecastModel, Errors errors, HttpServletRequest request, final ModelMap modelMap) throws Exception
{
/* I am trying to access the months related data i.e. quantiy that user entered through the text fields in the above table. */
ForecastServiceClient.createForecast(forecastModel);
return PasConstants.FORECAST_SUCCESS;
}
My question is, how to capture user entered data into a list and pass it to the the controller class?
Do i need to create a separate class for 12 months and a year?
Do I need to access them using a public List<String> getMonthsAndYear() {..} inside my 'Forecast' class since these months and a current year will be a part of this class only.
How do i iterate through list of months inside the JSP using JSTL? I do not want to use scriplet here.
Please, help me how to approach this problem so that the data entered by the user into input fields can be posted to the controller method for further processing.
Thanks,