1

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?

Sean O'Toole
  • 4,304
  • 6
  • 35
  • 43
user1811660
  • 125
  • 1
  • 8

2 Answers2

0

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 );
}
stg
  • 2,757
  • 2
  • 28
  • 55
0

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" />
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555