2011-06-29 103 views
4

我只是看不到它。我想做下面的等價物:在Struts2/OGNL中大寫整個單詞

listValue="%{capitalize(remoteUserName)}" 

裏面的一個s:select標籤。

根據struts文檔http://struts.apache.org/2.0.11.2/struts2-core/apidocs/com/opensymphony/xwork2/inject/util/Strings.html,存在大寫函數。我已經嘗試了上面的和Strings.capitalize嘗試使用remoteUserName。

徘徊在OGNL文檔的剩餘部分http://incubator.apache.org/ognl/,我沒有看到立即用這種方式進行大寫的方法。

那麼當使用struts 2標籤時,大寫的語法是什麼?

編輯:

我認識到,我提出的想法是利用剛單詞的第一個字母。真的,我希望大寫字母中的每個字符。

回答

5

下面是使用com.opensymphony.xwork2.inject.util.Strings的一個例子(已經過測試)

<s:property value="@[email protected](myString)"/> 

這需要靜態方法調用被啓用,這樣做簡單地添加,

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

到struts.xml的

編輯:只是讓其他人知道(你可能已經這樣做),你可以使用任何的我方法java.lang.String ie:myString.toUpperCase()是一個有效的表達式,您可以使用正則表達式和java.lang.String方法replaceFirstreplaceAll來實現所需的結果。

如果com.opensymphony.xwork2.inject.util.Strings 利用方法不能滿足您的需求了這個問題涵蓋了其他方法,這可能是有用的:How to capitalize the first character of each word in a string

+0

'」正是我所尋找的解決方案類型。我的struts.xml文件中已經有了allowStaticMethodAccess。但是,我誤以爲我在找什麼。您的修補程序不會做廣告,但我真的需要大寫字母。這是我的溝通錯誤。 – demongolem

+0

這很容易,你不需要staticMethodAccess,只需寫myString.toUppercase() – Quaternion

+0

更改你的評論myString.toUpperCase(),我可以接受你的解決方案:)謝謝。 – demongolem