使用< f:convertDateTime>格式化日期.并将其显示在< h:outputText>中 [英] Format the date using <f:convertDateTime> and display it in the <h:outputText>

查看:131
本文介绍了使用< f:convertDateTime>格式化日期.并将其显示在< h:outputText>中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在h:outputText中显示类似"2010-10-20 by Mary"的内容.日期值存储在名为date1的MBean字段中,而用户名存储在名为username的MBean字段中.我使用以下EL表达式和UI控件:

I want to display something like "2010-10-20 by Mary" in the h:outputText. The date value is stored inside the MBean 's field called date1 while the user name is stored inside the MBean 's field called username. I use the following EL expression and UI control:

<h:outputText value="#{MBean.date1} by #{MBean.username}">
   <f:convertDateTime pattern="YYYY-MM-DD" timeZone="#{configMB.timeZone}" />
</h:inputText>

可以显示该值.但是,它将忽略f:convertDateTime指定的日期格式.无论我如何更改数据格式,它都始终显示类似"Mary的 2010-06-08 12:35:22.0 ".我怎么解决这个问题??

The value can be displayed .However, it ignores the date format specified by f:convertDateTime. No matter how I change the data format, it always display something like "2010-06-08 12:35:22.0 by Mary". How can I solve this problem??

更新:Zenzen的解决方案适用于以下代码更改.

Update :Zenzen 's solution works with the following code changes.

<h:outputFormat value="{0, date, yyyy-MM-dd} by #{1}">
    <f:param value="#{MBean.date1}" />
    <f:param value="#{MBean.username}" />
</h:outputFormat>

但是我可以使用类似h:outputFormat<f:param>的方法来格式化只读h:inputText的值吗?有时显示的值太长了,使用<h:outputFormat>会生成span标记,其中包含格式化后的消息.我想要具有类似<input type="text">的效果,UI控件具有固定的长度,用户可以滚动查看该消息如果消息太长.或者,如何使用CSS或javascript格式化使行为看起来像<input type="text">的span标签?

However can I format the value of a read-only h:inputText using the method likes h:outputFormat and <f:param>? Sometimes the value displayed is so long and using <h:outputFormat> will generate the span tag which encloses the formatted message .I want to have an effect like <input type="text"> , which the UI control has the fixed length and user can scroll to see the message if the message is too long. Or alternative , how can I format the span tag that make the behavior looks like a <input type="text"> using css or javascript?

推荐答案

您可以执行以下操作:

<h:outputFormat value="{0, date, yyyy-MM-dd} by #{MBean.username}">
    <f:param value="#{MBean.date1}" />
</h:outputFormat>

我确定它可以与value="{0, date, yyyy-MM-dd}"一起使用,但不确定添加"by #{MBean.username}"后一切是否正常.

I'm sure it will work with value="{0, date, yyyy-MM-dd}" not sure if evertyhing will be ok after adding "by #{MBean.username}" though.

这篇关于使用&lt; f:convertDateTime&gt;格式化日期.并将其显示在&lt; h:outputText&gt;中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆