开发者

Capitalizing an entire word in Struts2 / OGNL

开发者 https://www.devze.com 2023-03-16 00:38 出处:网络
I just can\'t see it.I want to do the equivalent of the following: listValue=\"%{capitalize(remoteUserName)}\"

I just can't see it. I want to do the equivalent of the following:

listValue="%{capitalize(remoteUserName)}"

inside an s:select tag.

According to the struts documentation http://struts.apache.org/2.0.11.2/struts2-core/apidocs/com/opensymphony/xwork2/inject/util/Strings.html there exists a capitalize function. I have tried both the above and Strings.capitalize to try to capitalize remoteUserName.

Wandering through what is left of OGNL documentation at http://incubator.apache.org/ognl/, I don't see a way immediately to capitalize in this way.

So what then is the syntax to capitalize when using struts 2 tags?

EDIT:

开发者_如何学编程

I realize that the idea I put forth was to capitalize just the first letter of the word. Really, I would like each character in the word capitalized.


Here is an example of using com.opensymphony.xwork2.inject.util.Strings (has been tested)

<s:property value="@com.opensymphony.xwork2.inject.util.Strings@capitalize(myString)"/>

This requires that static method invocation be enabled, to do that simply add,

<struts>
    <constant name="struts.ognl.allowStaticMethodAccess" value="true"/> 
</struts>

into struts.xml

Edit: Just so others know (you probably already do) you can use any of the methods of java.lang.String ie: myString.toUpperCase() is a valid expression and you could use a regular expression and the java.lang.String methods replaceFirst or replaceAll to achieve the desired result.

If com.opensymphony.xwork2.inject.util.Strings capitalize method does not meet your needs this question covers other methods which might be useful: How to capitalize the first character of each word in a string

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号