• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

s:text issue Struts 2

 
Ranch Hand
Posts: 399
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Below code does not work, does not recognize package.properties
-------------------------------------------------------------
<s:text name="HelloWorld.message" />



Below code works and recognizes package.properties
--------------------------------------------------
<s:i18n name="test.package" >
<s:text name="HelloWorld.message" />
</s:i18n>

struts.xml
--------------
<struts>

<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />

<package name="test" namespace="/test" extends="struts-default">

<action name="HelloWorld" class="test.HelloWorld">
<result>/test/HelloWorld.jsp</result>
</action>

<action name="Hello" class="test.Hello">
<result>/test/HelloWorld.jsp</result>
</action>
</package>

<!-- Add packages here -->

</struts>

My .class files and package.properties are in test folder.

Could any one point whats the issue ?

Thank you
Ayub
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am also learning Struts 2 and just figured out the following:

If your action classes extend a common super class, HelloSupport, for example, then name your property file as 'HelloSupport.properties' and put it in the root folder of the package.

Hope that helps.

Haitao
 
Ayub ali khan
Ranch Hand
Posts: 399
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Haitao,

sorry that did not work..

I have a HelloWorld class which is extending ActionSupport. I renamed package.properties to HelloWorld.properties and copied in the root package..still <s:text name="HelloWorld.message"/> does not print the value defined for HelloWorld.message in HelloWorld.properties file..

Below is the code for HelloWorld.java
---------------------------------------

public class HelloWorld extends ActionSupport {
public static final String MESSAGE = "Hello.message";
public String execute() throws Exception{
setMessage(getText(MESSAGE));

return SUCCESS;
}
private String message;

public void setMessage(String message){
this.message = message;
}

public String getMessage() {
return message;
}

}

Any other thoughts..?

Thanks
Ayub
 
Haitao Lok
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ayub,

I had the 'struts2-blank' working on my PC which looks like what you are playing with now. Have a look at the documentation on i18n at
http://cwiki.apache.org/WW/internationalization.html

And please let me know how it goes.

Haitao
 
Ayub ali khan
Ranch Hand
Posts: 399
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Haitao,

sorry for the delayed response.You are right I am playing with Struts blank application. I went through your link however I am still not able to figure out why <s:text name="Hello.message"/> does not work

however if I use the s:i18n tag it works.

I will do further research why its not working..

<s:text name="Hello.message">

The Default Message That Will Be Displayed
</s:text>

<br>
<s:i18n name="test.package" >
<s:text name="webname1" />
</s:i18n>

the output of the above is as shown below..
----------------------------------------


The Default Message That Will Be Displayed
www.javaranch.com

s:i18n is finding the resource bundle..just s:text is not able to locate it. Strange

Thank you for helping me out !!!

Regards
Ayub
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried naming your .properties-file with a language specific suffix?
Something like package_en.properties should do the trick. I'm using the blank.war-file too and naming it this way worked for me.
 
Ayub ali khan
Ranch Hand
Posts: 399
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Andr� that did not work..I am not understanding why i18n tag pics up properties from my properties file where as s:text is not able to identify the properties file...?

any thing missing in the below code ?
------------------------------------------
<s:text name="HelloWorld.message">

The Default Message That Will Be Displayed
</s:text>
------------------------------------------

I have renamed package.properties to package_en.properties

Thank you for all the help !!!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was scratching my head on the same problem. Finally, noticed that my Class was not extending ActionSupport. Making my Class extend ActionSupport fixed the problem for me.
reply
    Bookmark Topic Watch Topic
  • New Topic