How can I convert a String in h:outputText? Here is the code of h:outputText:
<h:outputText value="#{item.label} : " />
I tried using this,
<s:convertStringUtils format="capitalize" trim="true"/>
But it gives me error : "no tag was defined for name: convertStringUtils"
There are several ways.
Use CSS text-transform: capitalize
property.
<h:outputText value="#{bean.text}" styleClass="capitalized" />
with
.capitalized {
text-transform: capitalize;
}
Create a custom Converter
.
<h:outputText value="#{bean.text}" converter="capitalizeConverter" />
with
@Override
public String getAsString(FacesContext context, UIComponent component, Object modelValue) {
if (modelValue == null || ((String) modelValue).isEmpty()) {
return null;
}
String string = (String) modelValue;
return new StringBuilder()
.append(Character.toTitleCase(string.charAt(0)))
.append(string.substring(1))
.toString();
}
Use OmniFaces' of:capitalize()
function.
<html ... xmlns:of="http://omnifaces.org/ui">
...
<h:outputText value="#{of:capitalize(bean.text)}" />
The <s:convertStringUtils>
which you're trying is not from Seam. It's from MyFaces Sandbox.
The following works with JSF 1.2 and Seam 2.x. It might work without Seam, but I can't recall exactly how Seam extends EL in Java EE 5.
<h:outputText value="#{item.label.toUpperCase()} : " />
<!-- If your string could be null -->
<h:outputText value="#{(item.label != null ? item.label.toUpperCase() : '')} : " />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With