我需要转换h:outputtext
问题描述:
我有一个rich:datatable来显示数据库上的记录,并且其中有一些列.这是一个示例:
I have a rich:datatable to show records on a DB and there are some columns in. Here is an example :
<rich:dataTable id="myTable" var="myItem" value="#{myList}">
<rich:column width="25%">
<h:outputText value="#{myItem.myValue}" />
</rich:column>
...
表显示记录很好.我想将 h:outputText
值显示为其他值(我是说将其转换).例如,反向字符串或它的查找和替换"结果.有numberConvertors,dateConvertors,但找不到Strings.客户端解决方案(如javascript,jquery)也可能是合理的.有什么建议吗?
Table shows the records fine. I want to show h:outputText
value as a different value (I mean convert it). For example, reversed string or "find&replaced" result of it. There are numberConvertors, dateConvertors but couldn't find for Strings. A client side solution (like javascript,jquery) also could be plausible. Any suggestions?
答
有numberConvertors,dateConvertors,但找不到字符串
只需自己创建一个.
@FacesConverter("myStringConverter")
public class MyStringConverter implements Converter {
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
// Write code here which converts the model value before displaying.
}
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
// Write code here which converts the submitted value before updating model.
// Note that this method isn't ever used in output text.
}
}
按以下方式使用它:
<h:outputText value="#{myItem.myValue}" converter="myStringConverter" />