简体   繁体   English

JSTL fmt:parseDate替代JSF

[英]JSTL fmt:parseDate substitute for JSF

How can I write: 我该怎么写:

<fmt:parseDate var="startDate" value="1/${param.month}/${param.year}"
    type="date" dateStyle="short" />

with JSF tags? 使用JSF标签? As <fmt> taglib is not supported in JSF2.0. 由于<fmt> taglib在JSF2.0中不受支持。 Above actually written in this way: 上面实际是这样写的:

<jsp:include page="LeaveCalendarMonthly.jsp" flush="true">
    <jsp:param name="month" value='1' />
    <jsp:param name="year" value='2013' />
</jsp:include>

Here the month and year values are sent by parameter to the LeaveCalendarMonthly.jsp page where it uses as: 在这里,月份和年份值通过参数发送到LeaveCalendarMonthly.jsp页面,该页面用作:

<fmt:parseDate var="startDate" value="1/${param.month}/${param.year}"
    type="date" dateStyle="short" />

The value calculates the date, and <fmt:parseDate> parses the value into date and a var 'startDate' holds the value for future use. 的值来计算的日期,以及<fmt:parseDate>解析值转换成日期和一个var “的startDate”保持用于将来使用的值。 How can I write the same thing using JSF tags?Please Help. 如何使用JSF标签编写相同的内容?请帮助。

There is no JSF tag substitute for the <fmt:parseDate> . 没有 JSF标记替代<fmt:parseDate>

This legacy JSTL tag converts String to Date , however when considering proper MVC design, the Date is in turn completely useless in the "view" side as the "view" is supposed to produce HTML code which only understands strings, not dates. 这个旧的JSTL标记将String转换为Date ,但是,考虑正确的MVC设计时, Date在“视图”侧反而完全没有用,因为“视图”应该生成仅能理解字符串,而不能理解日期的HTML代码。 You'd basically need to convert it back to string again. 您基本上需要再次将其转换回字符串。 As JSF strictly follows MVC ideology, there's no such thing as <fmt:parseDate> in JSF. 由于JSF严格遵循MVC意识形态,因此JSF中没有<fmt:parseDate>之类的东西。 In fact, you should be doing this job in the model, perhaps in flavor of a custom component. 实际上,您应该在模型中进行此工作,也许要使用自定义组件。

Your concrete functional requirement is not entirely clear, but so far it look much like that you need to convert a homegrown calendar thing from legacy JSP/JSTL to JSF. 您的具体功能要求尚不完全清楚,但到目前为止,您似乎很需要将本地日历文件从旧版JSP / JSTL转换为JSF。 In that case, it's so much easier to grab an existing JSF component such as PrimeFaces <p:calendar> . 在这种情况下,抓住现有的JSF组件(例如PrimeFaces <p:calendar>要容易得多。 This way it's a matter of 这样就可以了

<p:calendar value="#{bean.date}" />

without the need to reinvent the whole wheel. 无需重新发明整个车轮。

<h:outputText value="#{something that points to the date you want to convert}"><f:convertDateTime pattern="dd/MM/yyyy" /></h:outputText>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM