我有一個Java bean,它存儲了我所稱的元數據(周開始日,節假日),我的JSP視圖將用於顯示日曆月。我使用JSTL,不EL,因爲公司只有JSP 1.2我在哪裏爲持有元數據來設置一個Java bean的默認值來設置月份日曆
<table align="center" border="1" cellpadding="3" cellspacing="0" width="100%" class="tableInternalBorder">
<tbody>
<tr>
<th width="180px" class="optionYellow">Sun</th>
<th width="180px">Mon</th>
<th width="180px">Tue</th>
<th width="180px">Wed</th>
<th width="180px">Thu</th>
<th width="180px">Fri</th>
<th width="180px" class="optionYellow">Sat</th>
</tr>
<c:forEach var="week" begin="1" end="${calendar.totalWeeks}" varStatus="status">
<tr>
<c:forEach var="cell" begin="${1+7*(week-1)}" end="${7+7*(week-1)}" step="1" varStatus="status"><c:set var="dayNo" value="${cell-calendar.weekStartDay+1}" />
<c:choose><c:when test="${calendar.weekStartDay>cell || (cell-calendar.weekStartDay+1)>calendar.totalDays}">
<td height="50" class="<c:out value="${calendar.cellColor[cell]}" />">* </td>
</c:when>
<c:otherwise>
<td valign="Top" height="75px" class="<c:out value="${calendar.cellColor[dayNo]}" />"><span class="calDayNo"><c:out value="${dayNo}" /></span><span class="calDayName"> <c:out value="${calendar.holidayName[dayNo]}" /></span><br>
<c:forEach var="dayEvent" items="${eventMap.byDay[dayNo]}" varStatus="status"><div class="eventContent" ><c:out value="${status.count}" />) <c:out value="${dayEvent.event_type_name}" />: <c:out value="${dayEvent.eventUser.lastName}" /></div></c:forEach></td>
</c:otherwise>
</c:choose>
</c:forEach>
</tr>
</c:forEach>
</tbody>
</table>
在這個bean我還保存一個月名稱的數組,這樣我可以在我看來這樣做。
<c:forEach var="month" items="${calendar.monthList}" varStatus="status">
<option value="<c:out value="${status.index}" />" <c:if test="${month == calendar.monthName}">selected</c:if>><c:out value="${month}" /></option>
</c:forEach>
我的問題是我在我的javabean中設置月份列表或生成日曆元數據的方法。下面是返回到元數據bean的方法(爲了清晰起見刪除了邏輯)。我應該在這個方法,這個類還是在Java bean中設置它。如果它應該放在Java bean中,我不知道該怎麼做。
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;
}
編輯:這是我做的基礎上,接受的答案
我改變了這一點:
<c:forEach var="month" items="${calendar.monthList}" varStatus="status">
<option value="<c:out value="${status.index}" />" <c:if test="${month == calendar.monthName}">selected</c:if>><c:out value="${month}" /></option>
</c:forEach>
這樣:
<c:set var="months">January,February,March,April,May,June,July,August,September,October,November,December</c:set>
<c:forTokens var="month" items="${months}" delims="," varStatus="status">
<option value="<c:out value="${status.index}" />" <c:if test="${month == calendar.monthName}">selected</c:if>><c:out value="${month}" /></option>
</c:forTokens>
*「我正在使用JSTL,而不是EL」* - 嗯?你在這段代碼中使用了兩者。 JSTL是那些''標籤。 EL是那些'$ {}'的東西。 –
BalusC
2010-11-05 14:53:29
你讓我每次在這個聲明! :)我只是澄清,我需要使用
jeff
2010-11-05 15:12:28