views:

31

answers:

1

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>

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??

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>

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?

+1  A: 

You can do something like this:

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

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.

Zenzen
It works!!Thanks so much .But 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?
That's a new and independent question. Ask a new question to HTML/CSS/JS boys. This question is been answered. Mark the most helpful answer accepted -well, there's only one :)
BalusC