0

I am developing a simple GUI in which i want username value to be fetched from ApplicationResources.properties file. My file contains following two lines :

label.username= Username
label.password=Password

I am using JSP containing struts 2 tag contains following snippet :

<s:textfield cssClass="login-inp" name="username" key="label.username" size="20" />

But when i run my project i see label.username that indicates value from properties file is not read.. am i missing something ? How to solve this problem ? Kindly help

thanks in advance

omkar sohani
  • 147
  • 3
  • 6
  • 17

2 Answers2

3

I am not sure where and how you have defined the properties file but when searching for resource bundles struts2 search them in a specific way

  1. ActionClass.properties.
  2. BaseClass.properties (all the way to Object.properties)
  3. Interface.properties (every interface and sub-interface)
  4. ModelDriven's model (if implements ModelDriven), for the model object repeat from 1
  5. package.properties (of the directory where class is located and every parent directory all the way to the root directory)
  6. search up the i18n message key hierarchy itself
  7. global resource properties (webwork.custom.i18n.resources) defined in webwork.properties

refer document for details /internationalization.

Additionally The Struts 2 key attribute can be used in the textfield tag to instruct the framework what value to use for the textfield's name and label attributes.Instead of providing those attributes and their values directly, you can just use the key attribute.

So either use name="username" key="label.username".

Just go through the official documents for details how this work and how framework search for the property files message-resource-files

Umesh Awasthi
  • 23,407
  • 37
  • 132
  • 204
  • Thank you so much for the information.. I am using eclipse indigo for developing the web application and I have kept ApplicationResources.properties file in /src folder.. – omkar sohani Jan 18 '12 at 18:27
  • @omkarsohani: i already describe the way framework textprovider looks for resource buldles and it does not matte which IDE you are using as long you are working as per framework conventions – Umesh Awasthi Jan 19 '12 at 01:25
1

Add the below line in your struts.xml file just on top of the first package defintion.

<constant name="struts.custom.i18n.resources" value="ApplicationResources" />

OR

Add struts.properties file in your src folder. And keep the below property in it.

struts.custom.i18n.resources=ApplicationResources