私は以下をやろうとしています。JSP で、「2013 年 10 月」、「2013 年 11 月」などの見出しを持つテーブルを作成しました。次の 12 か月間です。つまり、「2014 年 9 月」までです。
たとえば、月が 2013 年 11 月の場合、システムは 2013 年 11 月を検出し、翌年の 2014 年 10 月まで 12 か月追加する必要があります。
12 の入力フィールド (各月に 1 つ) があり、それらは 1 つの行にあります。ユーザーは、このテーブルに動的に新しい行を追加でき、入力フィールドのいずれかの月の数量値をこれらのテキスト フィールドに入力できます。
<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,