You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Kaizar Amin <am...@cs.unt.edu> on 2005/09/27 10:18:53 UTC

How to remove the unwanted ???en_US string from ActionMessages

Hello all,

I am facing a wierd problem in my application. I want to add an
ActionMessage in the ACTION (LoginAction) class and then display the
message in the JSP page. In the JSP page, the messages are found without a
problem (so my ApplicationResources.properties configuration is fine),
however while prinintg them, the string "???en_US" and "???" gets attached
to my message before and after respectively.

???en_US.<my-message>???

How do I get rid of these strings???

I searched the discussion-list for similar problems/solutions and found
this thread:

http://www.mail-archive.com/user@struts.apache.org/msg27565.html

However, the solution in that threads talks about using the presentation
logic as follows:

 <html:messages id="errmsgs">
     <li><bean:write name="errmsgs"/></li>
 </html:messages>

But thats exactly how I am doing also. But for me it still gives the error.
Below is the configuration and code snippets that I am using:

In struts-config,xml
====================
<message-resources parameter="myApp.ApplicationResources" null="false"/>


In LoginAction.java
====================
if (username == null || username.trim().length() == 0){
      ActionMessages messages = new ActionMessages();
      ActionMessage message = new ActionMessage("Username/Password cannot
be empty");
      messages.add("credentials.empty", message);
      saveMessages(request,messages);

In the JSP page
====================
<html:messages id="message" message="true">
 <div class="success">
   <bean:write name="message"/><br>
 </div><br/>
</html:messages>

The output I get is
====================
 ???en_US.Username/Password cannot be empty???

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to remove the unwanted ???en_US string from ActionMessages

Posted by Aladin Alaily <st...@aladin.ca>.
Hi Amin,

Writting this:

 >ActionMessage message = new ActionMessage("Username/Password cannot
 > be empty");

will not solve the problem.

What you need to do to get rid of the following:


 >  ???en_US.Username/Password cannot be empty???

is:

1) Add a key/value pair to your application.properties file:
key1=Username/Password cannot be empty

2) You need to change the construction of your ActionMessage:
ActionMessage message = new ActionMessage("key1");

This will solve you problem.

Good luck.
Aladin




Kaizar Amin wrote:
> Hi Atta,
> 
> As per your suggestions, I changed the code to
> 
> if (username == null || username.trim().length() ==0 ){
>       ActionMessages messages = new ActionMessages();
>       ActionMessage message = new ActionMessage("Username/Password cannot
> be empty");
>       messages.add(ActionMessages.GLOBAL_MESSAGE, message);
>       saveMessages(request,messages);
> 
> But even this doesnt solve my problem. The output I get is:
> 
>  ???en_US.Username/Password cannot be empty???
> 
> 
>>Hi there,
>>
>>try this:
>>
>>if (username == null || username.trim().length() == 0){
>>ActionMessages messages = new ActionMessages();
>>ActionMessage message = new ActionMessage("credentials.empty");
>>
>>
>>>messages.add(ActioneMessages.GLOBAL_ERROR, message);
>>>saveMessages(request,messages);
>>
>>
>>}
>>
>>Basically, the thing to note here that ActionMessage takes a key from the
>>resource file which I assumed "credentails.empty" is. The first parameter
>>of
>>the ActionMessges.add(...) is the property against which error is being
>>stored or the generic global_error constant.
>>
>>HTH.
>>
>>ATTA
>>
>>
>>
>>
>>On 9/27/05, Kaizar Amin <am...@cs.unt.edu> wrote:
>>
>>>Hello all,
>>>
>>>I am facing a wierd problem in my application. I want to add an
>>>ActionMessage in the ACTION (LoginAction) class and then display the
>>>message in the JSP page. In the JSP page, the messages are found without
>>>a
>>>problem (so my ApplicationResources.properties configuration is fine),
>>>however while prinintg them, the string "???en_US" and "???" gets
>>>attached
>>>to my message before and after respectively.
>>>
>>>???en_US.<my-message>???
>>>
>>>How do I get rid of these strings???
>>>
>>>I searched the discussion-list for similar problems/solutions and found
>>>this thread:
>>>
>>>http://www.mail-archive.com/user@struts.apache.org/msg27565.html
>>>
>>>However, the solution in that threads talks about using the presentation
>>>logic as follows:
>>>
>>><html:messages id="errmsgs">
>>><li><bean:write name="errmsgs"/></li>
>>></html:messages>
>>>
>>>But thats exactly how I am doing also. But for me it still gives the
>>>error.
>>>Below is the configuration and code snippets that I am using:
>>>
>>>In struts-config,xml
>>>===================> <message-resources
>>>parameter="myApp.ApplicationResources" null="false"/>
>>>
>>>
>>>In LoginAction.java
>>>===================> if (username == null || username.trim().length() ==
>>>0){
>>>ActionMessages messages = new ActionMessages();
>>>ActionMessage message = new ActionMessage("Username/Password cannot
>>>be empty");
>>>messages.add("credentials.empty", message);
>>>saveMessages(request,messages);
>>>
>>>In the JSP page
>>>===================> <html:messages id="message" message="true">
>>><div class="success">
>>><bean:write name="message"/><br>
>>></div><br/>
>>></html:messages>
>>>
>>>The output I get is
>>>===================> ???en_US.Username/Password cannot be empty???
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to remove the unwanted ???en_US string from ActionMessages

Posted by Martin Gainty <mg...@hotmail.com>.
when you construct your ActionMessage
the first parameter is the key into the MessageResource..

the second parameter is the resource <OR string literal you wish to supply>
assuming

<message-resource parameter="classname" [null="true|false"] [key="name"]>
<html lang="en">

in this case if resource is true then your app will reference the key value 
("name") located within
$webapp_home/classes/com/OrganisationName/app_en.properties

HTH,
Martin-
----- Original Message ----- 
From: "Kaizar Amin" <am...@cs.unt.edu>
To: "atta-ur rehman" <at...@gmail.com>
Cc: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Tuesday, September 27, 2005 7:20 AM
Subject: Re: How to remove the unwanted ???en_US string from ActionMessages


Hi Atta,

As per your suggestions, I changed the code to

if (username == null || username.trim().length() ==0 ){
      ActionMessages messages = new ActionMessages();
      ActionMessage message = new ActionMessage("Username/Password cannot
be empty");
      messages.add(ActionMessages.GLOBAL_MESSAGE, message);
      saveMessages(request,messages);

But even this doesnt solve my problem. The output I get is:

 ???en_US.Username/Password cannot be empty???

> Hi there,
>
> try this:
>
> if (username == null || username.trim().length() == 0){
> ActionMessages messages = new ActionMessages();
> ActionMessage message = new ActionMessage("credentials.empty");
>
>> messages.add(ActioneMessages.GLOBAL_ERROR, message);
>> saveMessages(request,messages);
>
>
> }
>
> Basically, the thing to note here that ActionMessage takes a key from the
> resource file which I assumed "credentails.empty" is. The first parameter
> of
> the ActionMessges.add(...) is the property against which error is being
> stored or the generic global_error constant.
>
> HTH.
>
> ATTA
>
>
>
>
> On 9/27/05, Kaizar Amin <am...@cs.unt.edu> wrote:
>>
>> Hello all,
>>
>> I am facing a wierd problem in my application. I want to add an
>> ActionMessage in the ACTION (LoginAction) class and then display the
>> message in the JSP page. In the JSP page, the messages are found without
>> a
>> problem (so my ApplicationResources.properties configuration is fine),
>> however while prinintg them, the string "???en_US" and "???" gets
>> attached
>> to my message before and after respectively.
>>
>> ???en_US.<my-message>???
>>
>> How do I get rid of these strings???
>>
>> I searched the discussion-list for similar problems/solutions and found
>> this thread:
>>
>> http://www.mail-archive.com/user@struts.apache.org/msg27565.html
>>
>> However, the solution in that threads talks about using the presentation
>> logic as follows:
>>
>> <html:messages id="errmsgs">
>> <li><bean:write name="errmsgs"/></li>
>> </html:messages>
>>
>> But thats exactly how I am doing also. But for me it still gives the
>> error.
>> Below is the configuration and code snippets that I am using:
>>
>> In struts-config,xml
>> ===================> <message-resources
>> parameter="myApp.ApplicationResources" null="false"/>
>>
>>
>> In LoginAction.java
>> ===================> if (username == null || username.trim().length() ==
>> 0){
>> ActionMessages messages = new ActionMessages();
>> ActionMessage message = new ActionMessage("Username/Password cannot
>> be empty");
>> messages.add("credentials.empty", message);
>> saveMessages(request,messages);
>>
>> In the JSP page
>> ===================> <html:messages id="message" message="true">
>> <div class="success">
>> <bean:write name="message"/><br>
>> </div><br/>
>> </html:messages>
>>
>> The output I get is
>> ===================> ???en_US.Username/Password cannot be empty???
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to remove the unwanted ???en_US string from ActionMessages

Posted by Kaizar Amin <am...@cs.unt.edu>.
Hi Atta,

As per your suggestions, I changed the code to

if (username == null || username.trim().length() ==0 ){
      ActionMessages messages = new ActionMessages();
      ActionMessage message = new ActionMessage("Username/Password cannot
be empty");
      messages.add(ActionMessages.GLOBAL_MESSAGE, message);
      saveMessages(request,messages);

But even this doesnt solve my problem. The output I get is:

 ???en_US.Username/Password cannot be empty???

> Hi there,
>
> try this:
>
> if (username == null || username.trim().length() == 0){
> ActionMessages messages = new ActionMessages();
> ActionMessage message = new ActionMessage("credentials.empty");
>
>> messages.add(ActioneMessages.GLOBAL_ERROR, message);
>> saveMessages(request,messages);
>
>
> }
>
> Basically, the thing to note here that ActionMessage takes a key from the
> resource file which I assumed "credentails.empty" is. The first parameter
> of
> the ActionMessges.add(...) is the property against which error is being
> stored or the generic global_error constant.
>
> HTH.
>
> ATTA
>
>
>
>
> On 9/27/05, Kaizar Amin <am...@cs.unt.edu> wrote:
>>
>> Hello all,
>>
>> I am facing a wierd problem in my application. I want to add an
>> ActionMessage in the ACTION (LoginAction) class and then display the
>> message in the JSP page. In the JSP page, the messages are found without
>> a
>> problem (so my ApplicationResources.properties configuration is fine),
>> however while prinintg them, the string "???en_US" and "???" gets
>> attached
>> to my message before and after respectively.
>>
>> ???en_US.<my-message>???
>>
>> How do I get rid of these strings???
>>
>> I searched the discussion-list for similar problems/solutions and found
>> this thread:
>>
>> http://www.mail-archive.com/user@struts.apache.org/msg27565.html
>>
>> However, the solution in that threads talks about using the presentation
>> logic as follows:
>>
>> <html:messages id="errmsgs">
>> <li><bean:write name="errmsgs"/></li>
>> </html:messages>
>>
>> But thats exactly how I am doing also. But for me it still gives the
>> error.
>> Below is the configuration and code snippets that I am using:
>>
>> In struts-config,xml
>> ===================> <message-resources
>> parameter="myApp.ApplicationResources" null="false"/>
>>
>>
>> In LoginAction.java
>> ===================> if (username == null || username.trim().length() ==
>> 0){
>> ActionMessages messages = new ActionMessages();
>> ActionMessage message = new ActionMessage("Username/Password cannot
>> be empty");
>> messages.add("credentials.empty", message);
>> saveMessages(request,messages);
>>
>> In the JSP page
>> ===================> <html:messages id="message" message="true">
>> <div class="success">
>> <bean:write name="message"/><br>
>> </div><br/>
>> </html:messages>
>>
>> The output I get is
>> ===================> ???en_US.Username/Password cannot be empty???
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to remove the unwanted ???en_US string from ActionMessages

Posted by atta-ur rehman <at...@gmail.com>.
Hi there,

try this:

if (username == null || username.trim().length() == 0){
ActionMessages messages = new ActionMessages();
ActionMessage message = new ActionMessage("credentials.empty");

> messages.add(ActioneMessages.GLOBAL_ERROR, message);
> saveMessages(request,messages);


}

Basically, the thing to note here that ActionMessage takes a key from the
resource file which I assumed "credentails.empty" is. The first parameter of
the ActionMessges.add(...) is the property against which error is being
stored or the generic global_error constant.

HTH.

ATTA




On 9/27/05, Kaizar Amin <am...@cs.unt.edu> wrote:
>
> Hello all,
>
> I am facing a wierd problem in my application. I want to add an
> ActionMessage in the ACTION (LoginAction) class and then display the
> message in the JSP page. In the JSP page, the messages are found without a
> problem (so my ApplicationResources.properties configuration is fine),
> however while prinintg them, the string "???en_US" and "???" gets attached
> to my message before and after respectively.
>
> ???en_US.<my-message>???
>
> How do I get rid of these strings???
>
> I searched the discussion-list for similar problems/solutions and found
> this thread:
>
> http://www.mail-archive.com/user@struts.apache.org/msg27565.html
>
> However, the solution in that threads talks about using the presentation
> logic as follows:
>
> <html:messages id="errmsgs">
> <li><bean:write name="errmsgs"/></li>
> </html:messages>
>
> But thats exactly how I am doing also. But for me it still gives the
> error.
> Below is the configuration and code snippets that I am using:
>
> In struts-config,xml
> ====================
> <message-resources parameter="myApp.ApplicationResources" null="false"/>
>
>
> In LoginAction.java
> ====================
> if (username == null || username.trim().length() == 0){
> ActionMessages messages = new ActionMessages();
> ActionMessage message = new ActionMessage("Username/Password cannot
> be empty");
> messages.add("credentials.empty", message);
> saveMessages(request,messages);
>
> In the JSP page
> ====================
> <html:messages id="message" message="true">
> <div class="success">
> <bean:write name="message"/><br>
> </div><br/>
> </html:messages>
>
> The output I get is
> ====================
> ???en_US.Username/Password cannot be empty???
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>