用于显示大型事件类型日历的 JSP 自定义标记

发布于 2024-09-30 00:45:56 字数 190 浏览 3 评论 0 原文

这可能是一个简单的问题,但是大家都用什么在jsp中显示简单的事件日历。我正在寻找现有的标签库,但除了calendarTag 之外没有真正找到任何东西。

我正在使用 Spring MVC 3.0、JodaTime。基本上只是想要一个 jsp 上的大日历,我可以在其中基于某种逻辑包含指向另一个寻呼机的链接。没什么特别的。

有什么想法吗?

This is probably a simple question, but what is everyone using to display a simple event calendar in jsp. I was looking for an existing taglib but didn't really find anything other than calendarTag.

I'm using Spring MVC 3.0, JodaTime. and basically just want a large calendar on a jsp where I can include links to another pager based on some logic. Not really anything fancy.

Any Thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灯角 2024-10-07 00:45:56

我会在控制器中创建日历,例如这样:

@Controller
public class CalendarController{

    private static final int START_OF_WEEK = DateTimeConstants.MONDAY;

    @RequestMapping("drawCalendar")
    public ModelAndView drawCalendar(@RequestParam("month") final int month,
        @RequestParam("year") final int year){
        final LocalDate monthStart = new LocalDate(year, month, 1);
        boolean endReached = false;
        LocalDate today = null;
        final List<List<LocalDate>> weeks1 = new ArrayList<List<LocalDate>>();
        while(!endReached){
            final List<LocalDate> thisWeek = new ArrayList<LocalDate>();
            for(int weekOffset = 0; weekOffset < 7; weekOffset++){
                if(today == null){
                    if(!endReached
                        && weekOffset == monthStart.getDayOfWeek()
                            - START_OF_WEEK){
                        today = monthStart;
                    }
                } else{
                    today = today.plusDays(1);
                    if(today.getMonthOfYear() != month){
                        today = null;
                        endReached = true;
                    }
                }
                thisWeek.add(today);
            }
            weeks1.add(thisWeek);
        }
        final List<List<LocalDate>> weeks = weeks1;

        final Map<String, Object> model = new HashMap<String, Object>();
        model.put("calendar", weeks);
        final ModelAndView modelAndView = new ModelAndView("calendar", model);
        return modelAndView;
    }
}

在 JSP 中我会迭代几周:(

<c:forEach items="${calendar}" var="week">
    <tr>
        <td>Mon</td>
        <td>Tue</td>
        <td>Wed</td>
        <td>Thu</td>
        <td>Fri</td>
        <td>Sat</td>
        <td>Sun</td>
    </tr>
    <tr>
        <c:forEach items="${week}" var="date">
            <td><c:out value="${date==null ? '' : date.dayOfWeek}"</td>
        </c:forEach>
    </tr>
</c:forEach>

当然,我大约 3 年没有编写任何 JSP 代码,如果出现问题,很抱歉)

I would create the calendar in the controller, for example like this:

@Controller
public class CalendarController{

    private static final int START_OF_WEEK = DateTimeConstants.MONDAY;

    @RequestMapping("drawCalendar")
    public ModelAndView drawCalendar(@RequestParam("month") final int month,
        @RequestParam("year") final int year){
        final LocalDate monthStart = new LocalDate(year, month, 1);
        boolean endReached = false;
        LocalDate today = null;
        final List<List<LocalDate>> weeks1 = new ArrayList<List<LocalDate>>();
        while(!endReached){
            final List<LocalDate> thisWeek = new ArrayList<LocalDate>();
            for(int weekOffset = 0; weekOffset < 7; weekOffset++){
                if(today == null){
                    if(!endReached
                        && weekOffset == monthStart.getDayOfWeek()
                            - START_OF_WEEK){
                        today = monthStart;
                    }
                } else{
                    today = today.plusDays(1);
                    if(today.getMonthOfYear() != month){
                        today = null;
                        endReached = true;
                    }
                }
                thisWeek.add(today);
            }
            weeks1.add(thisWeek);
        }
        final List<List<LocalDate>> weeks = weeks1;

        final Map<String, Object> model = new HashMap<String, Object>();
        model.put("calendar", weeks);
        final ModelAndView modelAndView = new ModelAndView("calendar", model);
        return modelAndView;
    }
}

and in the JSP I would iterate over the weeks:

<c:forEach items="${calendar}" var="week">
    <tr>
        <td>Mon</td>
        <td>Tue</td>
        <td>Wed</td>
        <td>Thu</td>
        <td>Fri</td>
        <td>Sat</td>
        <td>Sun</td>
    </tr>
    <tr>
        <c:forEach items="${week}" var="date">
            <td><c:out value="${date==null ? '' : date.dayOfWeek}"</td>
        </c:forEach>
    </tr>
</c:forEach>

(of course I haven't written any JSP code in about 3 years, so sorry if something is wrong)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文