I need to convert h:outputtext

一个人想着一个人 提交于 2019-12-24 07:17:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!