【问题标题】:I need to convert h:outputtext我需要转换 h:outputtext
【发布时间】:2012-10-29 14:15:32
【问题描述】:
我有一个丰富的数据表来显示数据库上的记录,其中有一些列。这是一个示例:
<rich:dataTable id="myTable" var="myItem" value="#{myList}">
<rich:column width="25%">
<h:outputText value="#{myItem.myValue}" />
</rich:column>
...
表格显示的记录很好。我想将 h:outputText 值显示为不同的值(我的意思是转换它)。例如,反转字符串或它的“查找和替换”结果。有 numberConvertors、dateConvertors 但找不到字符串。客户端解决方案(如 javascript、jquery)也可能是合理的。有什么建议吗?
【问题讨论】:
标签:
javascript
jsf
richfaces
【解决方案1】:
有 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" />
【解决方案2】:
字符串值没有默认转换器。
您可以在这里做的最简单的事情是编写一个替代的 getMyValue() 方法。
<h:outputText value="#{myItem.myModifiedValue}" />
在你的豆子里……
public String getMyModifiedValue() {
return doSomethingwith( this.myValue );
}