我在哪里为持有元数据来设置一个Java bean的默认值来设置月份日历
问题描述:
我有一个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