1

I have a JSP that contains lots of s:text's and s:property's. There are also some s:iterator's with s:text's inside them. The issue I'm facing is that once I submit the form and try to show something on the same JSP, all the s:text's and s:property's which used to display the values corresponding to properties started displaying just the property names.

Like

login.username=Username

JSP:

<s:text name="login.username" />

On submitting the form and returning to the same JSP, the property name: login.username shows up on the page where it used to display Username. Any idea why?

Roman C
  • 49,761
  • 33
  • 66
  • 176
mystarrocks
  • 4,040
  • 2
  • 36
  • 61
  • 2
    post your Action and your struts.xml too, and make a try using getText(): http://stackoverflow.com/questions/711093/how-do-you-get-a-struts2-value-from-the-properties-file-programatically – Andrea Ligios Apr 12 '13 at 12:17
  • getText() usage worked fine for me. But on the initial page load, simple sufficed which is not the case after the loading of the same page on form submission. Why is that the case? – mystarrocks Apr 12 '13 at 13:14
  • 1
    There's not enough information here to help diagnose the problem. – Dave Newton Apr 12 '13 at 17:41

2 Answers2

1

It's likely no i18n interceptor on the action stack or you don't have resource bundles for the used locale or default locale used by the JVM.

Essentially, the i18n Interceptor pushes a locale into the ActionContext map upon every request. The framework components that support localization all utilize the ActionContext locale.


Roman C
  • 49,761
  • 33
  • 66
  • 176
  • Alright, I think this could be the reason- my action has an interceptor associated with it. login.jsp form Submit -> Interceptor -> LoginAction.java -> login,jsp and there you go all the resource property references are empty! Of course it all just worked when I made use of the global resource bundle but I'd prefer to know if there was a way to access package.properties like before and still access all the properties in this case. – mystarrocks Apr 13 '13 at 07:18
  • It's an option #5 from the [localization guide](http://struts.apache.org/release/2.3.x/docs/localization.html) – Roman C Apr 13 '13 at 07:35
  • Does that mean I have to relocate my package.properties? I previously had it under ~/com/example/login. My action is under ~/com/example/login/action and my interceptor's under ~/com/example/login/interceptor. Do you mean I need to place the package.properties in the same folder as global.properties (parent of com folder) and get rid of global.properties? – mystarrocks Apr 13 '13 at 07:47
  • it doesn't matter it will traverse the package hierarchy – Roman C Apr 13 '13 at 08:17
0

If you use one properties file per action to store your i18n messages then you can have following situation:

ActionA.java -> 1.jsp
ActionB.java -> 1.jsp
ActionA.properties (all i18n messages are defined only here)

On ActionA everything is OK, but after submit on ActionB stuts cannot find corresponding i18n messages.

Maksym Demidas
  • 7,707
  • 1
  • 29
  • 36