Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere do I specify default values for a Java bean that holds meta data to format a Month Calendar
    text
    copied!<p>I have a Java bean which stores what I am calling meta data (week start day, any holidays) that my JSP view will use to display a Calendar Month. I am using JSTL, not EL, since company only has jsp 1.2</p> <pre><code> &lt;table align="center" border="1" cellpadding="3" cellspacing="0" width="100%" class="tableInternalBorder"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;th width="180px" class="optionYellow"&gt;Sun&lt;/th&gt; &lt;th width="180px"&gt;Mon&lt;/th&gt; &lt;th width="180px"&gt;Tue&lt;/th&gt; &lt;th width="180px"&gt;Wed&lt;/th&gt; &lt;th width="180px"&gt;Thu&lt;/th&gt; &lt;th width="180px"&gt;Fri&lt;/th&gt; &lt;th width="180px" class="optionYellow"&gt;Sat&lt;/th&gt; &lt;/tr&gt; &lt;c:forEach var="week" begin="1" end="${calendar.totalWeeks}" varStatus="status"&gt; &lt;tr&gt; &lt;c:forEach var="cell" begin="${1+7*(week-1)}" end="${7+7*(week-1)}" step="1" varStatus="status"&gt;&lt;c:set var="dayNo" value="${cell-calendar.weekStartDay+1}" /&gt; &lt;c:choose&gt;&lt;c:when test="${calendar.weekStartDay&gt;cell || (cell-calendar.weekStartDay+1)&gt;calendar.totalDays}"&gt; &lt;td height="50" class="&lt;c:out value="${calendar.cellColor[cell]}" /&gt;"&gt;*&amp;nbsp;&lt;/td&gt; &lt;/c:when&gt; &lt;c:otherwise&gt; &lt;td valign="Top" height="75px" class="&lt;c:out value="${calendar.cellColor[dayNo]}" /&gt;"&gt;&lt;span class="calDayNo"&gt;&lt;c:out value="${dayNo}" /&gt;&lt;/span&gt;&lt;span class="calDayName"&gt; &lt;c:out value="${calendar.holidayName[dayNo]}" /&gt;&lt;/span&gt;&lt;br&gt; &lt;c:forEach var="dayEvent" items="${eventMap.byDay[dayNo]}" varStatus="status"&gt;&lt;div class="eventContent" &gt;&lt;c:out value="${status.count}" /&gt;) &lt;c:out value="${dayEvent.event_type_name}" /&gt;: &lt;c:out value="${dayEvent.eventUser.lastName}" /&gt;&lt;/div&gt;&lt;/c:forEach&gt;&lt;/td&gt; &lt;/c:otherwise&gt; &lt;/c:choose&gt; &lt;/c:forEach&gt; &lt;/tr&gt; &lt;/c:forEach&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>In this bean I also storing an array of month names so that I can do this in my view.</p> <pre><code>&lt;c:forEach var="month" items="${calendar.monthList}" varStatus="status"&gt; &lt;option value="&lt;c:out value="${status.index}" /&gt;" &lt;c:if test="${month == calendar.monthName}"&gt;selected&lt;/c:if&gt;&gt;&lt;c:out value="${month}" /&gt;&lt;/option&gt; &lt;/c:forEach&gt; </code></pre> <p>My question is do I set the month list in my javabean or the method which generates the meta data for the calendar. Here is the method that returns to meta data bean (with logic removed for clarity). Should I set it in this method, this class, or in the Java bean. If it should go in the Java bean, I am not sure how to do that. </p> <pre><code>public EBCalendar getCalendarMeta (HttpServletRequest request) { //Get any request parameters int iYear = STKStringUtils.nullIntconv(request.getParameter("iYear")); int iMonth = STKStringUtils.nullIntconv(request.getParameter("iMonth")); EBCalendar ebCal = new EBCalendar(); // Get the current month and year Calendar ca = new GregorianCalendar(); int curYear = ca.get(Calendar.YEAR); int curMonth = ca.get(Calendar.MONTH); // If request parameters are null use todays calendar if (iYear == 0) { iYear = curYear; iMonth = curMonth; } ebCal.setCurYear(curYear); ebCal.setCurMonth(curMonth); ebCal.setSelYear(iYear); ebCal.setSelMonth(iMonth); ebCal.setTotalWeeks(iTotalweeks); ebCal.setTotalDays(totalDays); ebCal.setWeekStartDay(weekStartDay); ebCal.setAbvMonthName(abvMonthName); ebCal.setMonthName(monthName); ebCal.setMonthList(monthList); ebCal.setHolidayName(getEBHolidayNameInMonth(iYear, iMonth)); ebCal.setCellColor(getWeekendHolidayColorMap(iYear, iMonth)); return ebCal; } </code></pre> <h1>EDIT: Here is what I did based on the accepted answer</h1> <p>I changed this:</p> <pre><code>&lt;c:forEach var="month" items="${calendar.monthList}" varStatus="status"&gt; &lt;option value="&lt;c:out value="${status.index}" /&gt;" &lt;c:if test="${month == calendar.monthName}"&gt;selected&lt;/c:if&gt;&gt;&lt;c:out value="${month}" /&gt;&lt;/option&gt; &lt;/c:forEach&gt; </code></pre> <p>to this:</p> <pre><code>&lt;c:set var="months"&gt;January,February,March,April,May,June,July,August,September,October,November,December&lt;/c:set&gt; &lt;c:forTokens var="month" items="${months}" delims="," varStatus="status"&gt; &lt;option value="&lt;c:out value="${status.index}" /&gt;" &lt;c:if test="${month == calendar.monthName}"&gt;selected&lt;/c:if&gt;&gt;&lt;c:out value="${month}" /&gt;&lt;/option&gt; &lt;/c:forTokens&gt; </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