Java 将h:outputText中的字符串转换为大写字符串?
如何转换h:outputText中的字符串?以下是h:outputText的代码:Java 将h:outputText中的字符串转换为大写字符串?,java,jsf,seam,Java,Jsf,Seam,如何转换h:outputText中的字符串?以下是h:outputText的代码: <h:outputText value="#{item.label} : " /> 我试着用这个 <s:convertStringUtils format="capitalize" trim="true"/> 但它给了我一个错误: “没有为name:convertStringUtils定义标记”在数据bean中创建getter方法 public String getCapi
<h:outputText value="#{item.label} : " />
我试着用这个
<s:convertStringUtils format="capitalize" trim="true"/>
但它给了我一个错误:
“没有为name:convertStringUtils定义标记”在数据bean中创建getter方法
public String getCapitalizeName(){
return StringUtils.capitalize(getName());
}
在xhtml上
<houtputText value="#{yourDataBean.capitalizeName}"/>
有几种方法
文本转换:大写
属性
与
。大写{
文本转换:大写;
}
与
...
您尝试的
不是来自Seam。它来自MyFaces Sandbox。正如@BalusC所说,您可以使用文本转换:大写代码>。但它会将句子中每个单词的第一个字母转换为大写。如果你的要求是这样,那是最好的答案,因为
1.更容易
2.文本转换:大写所有主要浏览器都支持代码>。
然而,如果你只想大写句子的第一个字母,你可以这样做
public String getLabel() {
if(label != null && !label.isEmpty()) {
return Character.toUpperCase(label.charAt(0)) + label.substring(1);
}
return label;
}
我不认为JBossSeam有一个标签。因为我认为这样的标签在apachemyfaces中是可用的。我对此不太了解。以下内容适用于JSF 1.2和Seam 2.x。如果没有Seam,它可能会工作,但我记不起Seam是如何在JavaEE5中扩展EL的
<h:outputText value="#{item.label.toUpperCase()} : " />
<!-- If your string could be null -->
<h:outputText value="#{(item.label != null ? item.label.toUpperCase() : '')} : " />
我不想转换成大写,我想大写。但这(数字5)也可以用于使其资本化。谢谢你的努力。哦,对了,固定答案:)CSS one是最简单的IMO。它纯粹是表示,对吗?在实现CSS选项时,我注意到如果字符串包含“/”或“-”。这个答案在两个方面是不正确的:1)大写和大写绝对不一样,大写只是大写的第一个字符。2) EL是空安全的,因此空检查没有意义,您只需直接使用{item.label.toUpperCase()}
;我没有意识到这一点。我看到在中指定了此评估行为。
<h:outputText value="#{item.label.toUpperCase()} : " />
<!-- If your string could be null -->
<h:outputText value="#{(item.label != null ? item.label.toUpperCase() : '')} : " />