wood burning stoves*
The moose likes Struts and the fly likes s:text issue Struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "s:text issue Struts 2" Watch "s:text issue Struts 2" New topic
Author

s:text issue Struts 2

Ayub ali khan
Ranch Hand

Joined: Oct 20, 2005
Posts: 380
    
    2
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


SCEA part I,TOGAF Foundation
Haitao Lok
Greenhorn

Joined: May 05, 2008
Posts: 8
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

Joined: Oct 20, 2005
Posts: 380
    
    2
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

Joined: May 05, 2008
Posts: 8
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

Joined: Oct 20, 2005
Posts: 380
    
    2
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
Andr� Cedik
Greenhorn

Joined: Mar 30, 2008
Posts: 8
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

Joined: Oct 20, 2005
Posts: 380
    
    2
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 !!!
Rajan Raman
Greenhorn

Joined: Dec 09, 2008
Posts: 1
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: s:text issue Struts 2
 
Similar Threads
Unhandled Exception while run the struts
S2: autocompleter - how to populate a list based on user's input?
Autocompleter Struts2 not working for me:: Please help
Ant: How to place resource files into bottom of package level structure?
Struts 2 Dojo autocompleter not working in Struts 2.0.14?