Reputation: 21
I am trying to use <c:forEach>
tag to loop in <html:select>
tag.
<html:select property="year" >
<s:iterator var="i" begin="${1}" end="${monthlyChargeForm.currentYear - 2000}" >
<s:set var="counter" value="${monthlyChargeForm.currentYear}"/>
<html:option value="${counter}">
<c:out value="${counter}"/>
</html:option>
<s:set var="counter" value="${counter-1}"/>
</s:iterator>
</html:select>
I am trying to list all the years from current year to YEAR : 2000 in the drop down.
But I am getting an empty dropdown.
Action class code that I've used:
// monthlyChargeForm.setCurrentYear(now.get(Calendar.YEAR) );
to get the current year.
public class MonthlyChargeAction extends Action {
private ActionMessages messages;
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws Exception {
ServletContext context = getServlet().getServletContext();
BACUtils bacUtils = new BACUtils();
String sessionStatus = HtmlBean.isSessionOut(request.getSession(false), context);
if(!Constants.SUCCESS_STATUS.equals(sessionStatus)) {
return mapping.findForward("sessionOut");
}
String accesssStatus = HtmlBean.isSessionValid(request.getSession(false), context,
Properties.ACCESS_PROFILE[8][0]);
if(!Constants.SUCCESS_STATUS.equals(accesssStatus)) {
return mapping.findForward("sessionOut");
}
MonthlyChargeForm monthlyChargeForm = (MonthlyChargeForm)form;
Reports reports = new Reports();
String sUser =(String) request.getSession().getAttribute("USERID");
String returnVal = "";
int i = 0;
try {
monthlyChargeForm.setFromDate(bacUtils.getDate());
monthlyChargeForm.setToDate(bacUtils.getDate());
Calendar now = Calendar.getInstance();
String fromDate = monthlyChargeForm.getFromDate();
String toDate = monthlyChargeForm.getToDate();
String curentDate = bacUtils.getDate();
monthlyChargeForm.setCurrentYear(now.get(Calendar.YEAR) );
System.out.println("Current Year :::::::::" +
monthlyChargeForm.getCurrentYear());
AuditTrial.insertLog(5,sUser,null,"General Reports Module Loaded
Successfully",(String)
request.getSession().getAttribute("OPER_TYPE"),"S",request.getRemoteAddr(),context);
if(monthlyChargeForm.getPageIndex() == null ||
monthlyChargeForm.getPageIndex().trim().length() == 0)
monthlyChargeForm.setPageIndex(Integer.toString(BACUtils.getIntVal(
monthlyChargeForm.getPageIndex())));
if(monthlyChargeForm.getMonth()!=null &&
monthlyChargeForm.getYear()!=null )
{
monthlyChargeForm.setMonthlyChargeReport(
reports.getMonthlyChargeData(monthlyChargeForm, 10, context));
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(Constants.SUCCESS_MAPPING);
return mapping.findForward(Constants.SUCCESS_MAPPING);
}
Upvotes: 1
Views: 3153
Reputation: 1
If you are trying to use foreach loop then you can try forEach
tag from JSTL core taglib.
<%@ taglib prefix="html" uri="http://struts.apache.org/tags-html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html:select property="year" >
<c:forEach varStatus="i" begin="${monthlyChargeForm.currentYear}" end="2000" step="-1">
<html:option value="${i.index}">
<c:out value="${i.index}"/>
</html:option>
</c:forEach>
</html:select>
Upvotes: 1