Note that there are some explanatory texts on larger screens.

plurals
  1. POStruts : for each loop
    text
    copied!<p>I am trying to use <code>foreach</code> loop in <code>Select</code> tag.</p> <pre><code>&lt;html:select property="year" &gt; &lt;s:iterator var="i" begin="${1}" end="${monthlyChargeForm.currentYear - 2000}" &gt; &lt;s:set var="counter" value="${monthlyChargeForm.currentYear}"/&gt; &lt;html:option value="${counter}"&gt; &lt;c:out value="${counter}"/&gt; &lt;/html:option&gt; &lt;s:set var="counter" value="${counter-1}"/&gt; &lt;/s:iterator&gt; &lt;/html:select&gt; </code></pre> <p>I am trying to list all the years from current year to YEAR : 2000 in the drop down. But I am getting empty drop-down.</p> <p>Action class code : I've used </p> <pre><code>// monthlyChargeForm.setCurrentYear(now.get(Calendar.YEAR) ); </code></pre> <p>to get the current year.</p> <pre><code>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 &amp;&amp; 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); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload