2008-12-07 61 views
0

我想學習如何使用Struts 2,並在我找到的教程之後創建了一個簡單的應用程序。如何翻譯Struts 2的驗證消息?

我創建了一個<MyActionClass>-validation.xml文件,我想知道如何將驗證消息轉換爲多種語言?

<field name="password"> 
    <field-validator type="requiredstring"> 
     <param name="trim">true</param> 
     <message>You have to enter a password.</message> 
       <!-- How can I localize this message? --> 
    </field-validator> 
</field> 

我可以從本地化的.properties文件中獲取消息,還是必須使用其他類型的驗證?

回答

1

好吧,我自己找到了。你必須創建該類的屬性文件,那麼你可以更改代碼從:

<message>You have to enter a password.</message> 

到:

<message key="[message key from the properties file]" />