问题
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>
...
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?
回答1:
There are numberConvertors, dateConvertors but couldn't find for Strings
Just create one yourself.
@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.
}
}
Use it as follows:
<h:outputText value="#{myItem.myValue}" converter="myStringConverter" />
回答2:
There are no defaultConverters for String values.
Simplest thing you can do here is to write an alternative getMyValue()-methode.
<h:outputText value="#{myItem.myModifiedValue}" />
and in your bean sth like
public String getMyModifiedValue() {
return doSomethingwith( this.myValue );
}
来源:https://stackoverflow.com/questions/13305044/i-need-to-convert-houtputtext