You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tony Dahbura <to...@dahbura.com> on 2005/06/02 03:08:01 UTC

help with messages using bean on jsp

I have a peculiar problem cropping up with Struts 1.2.7...

When I add an actionError to using my form bean and then go to display 
it in the html jsp page I get the following:

    * ???en_US.userid is a required value.???
    * ???en_US.password is a required value.???

My struts-config.xml file looks like this for the message resources:
<message-resources null="false" 
parameter="tonyapp.ApplicationMessageResources"/>

If I turn the null to true I get nothing rendered-the 
ApplicationMessageResources file is in the proper location and moving it 
results in the message not being displayed (as a test).  The HTML 
elements that are attempting to output the values are:
<logic:messagesPresent>
          <ul>
                <html:messages id="errmsgs">
                      <li><bean:message name="errmsgs"/></li>
                </html:messages>
           </ul>
 </logic:messagesPresent>

And finally the loginForm java code that is doing this is at:
 if (getUsername() == null || getUsername().length() < 1) {
            errors.add( ActionMessages.GLOBAL_MESSAGE, new 
ActionMessage("global.required", "userid" ) );
 }
 if (getPassword() == null || getPassword().length() < 1) {
            errors.add( ActionMessages.GLOBAL_MESSAGE, new 
ActionMessage("global.required", "password") );
  }

The properties file looks like this:
global.required={0} is a required value.

I am developing with Eclipse and using tomcat 5.5 with jdk 1.5.  This is 
baffling to me as to why it is prepending the en_US to the value of the 
key after it looks it up.  I actually get the message and the 
substitution but somehow the en_US gets put in and it flags an error 
that it cannot find the message (indicated by the ???).

On another note I have had quite a bit of difficulty using the 
bean:write tags with bean properties that do not return Strings...Some 
of my beans return integers and the bean:write tag just fails and causes 
the rest of the page after the failure to not even render....Not sure if 
it is something with this particular library or not..

Any help would be very appreciated.  I looked through the release notes 
on the new struts 1.2.7 and did not see any fixes....

Thanks,
Tony



Re: help with messages using bean on jsp

Posted by Martin Gainty <mg...@hotmail.com>.
Tony-
This is ok if you dont want to use locale-specific resource strings (you 
just want to display the non-locale specific string)
If you do want to use locale-specific resource strings (from your resource 
bundle) I would not use <bean:display but <bean:message 
key="PutFullyQualfiedNameOfKeyHere" />
All the same I'm glad the former solution worked for you,
Martin-
----- Original Message ----- 
From: "Tony Dahbura" <to...@dahbura.com>
To: "Martin Gainty" <mg...@hotmail.com>
Cc: "Struts Users Mailing List" <us...@struts.apache.org>; "Aman A" 
<am...@gmail.com>
Sent: Sunday, June 05, 2005 3:22 PM
Subject: Re: help with messages using bean on jsp


> All:
> Figured out the problem....:
> My JSP page was trying to display the messages using the following code:
> <ul>
>    <html:messages id="errmsgs">
>            <li><bean:message name="errmsgs"/></li>
>     </html:messages>
> </ul>
>
> I should have used a <bean:write name="errmsgs"/>  tag instead.  I think 
> the <bean:mesage> tag was trying to lookup the message as the key to a 
> message rather than just displaying the message?
>
> Thanks,
> Tony
>
>
> Martin Gainty wrote:
>
>> Tony-
>> to allow access by your Struts app's bean tag set the struts-config.xml
>> <message-resources parameter=test.ApplicationResources"/>
>> (ApplicationResources.properties is located in test folder off root)
>> Now you can have multiple <message-resources with key="PropertyKey" to 
>> identify the particular ApplicationResources implementation
>>
>> You can use bean:message to pull the parameter and substitute your 
>> parameters in
>> <bean:message key="label.welcome" arg0="Ralph" arg1="Nader"/>
>>
>> But JSTL is better suited for internationalisation and message formatting 
>> so entering the bundle identifier in web.xml
>> <context-param>
>>  <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
>>  <param-value>ApplicationResources</param-value>
>> </context-param>
>>
>> later on in your jsp
>> <%@ taglib uri=http://java.sun.com/jstl/fmt prefix="fmt"%>
>> and now do your substitution..
>> <fmt:message key="buttonsubmit" bundle="${bundleToUse}"/> where 
>> bundleToUse is ApplicationResources.properties
>> In this way all of your strings will be assigned to locale specific 
>> properties file
>>
>> HTH,
>> Martin-
>> ----- Original Message ----- From: "Tony Dahbura" <to...@dahbura.com>
>> To: "Martin Gainty" <mg...@hotmail.com>
>> Cc: "Struts Users Mailing List" <us...@struts.apache.org>
>> Sent: Thursday, June 02, 2005 9:59 PM
>> Subject: Re: help with messages using bean on jsp
>>
>>
>>> I do not have a ApplicationMessageResources_en_US.properties but I do 
>>> have a ApplicationMessageResources.properties file with the following 
>>> properties:
>>> global.required={0} is a required value.
>>>
>>> As can be seen the actual substitution is taking place.  I pass "userid" 
>>> and it replaces the string with "userid is a required value"
>>> so the substitution is working but the message is prepended with en_US
>>>
>>> Any help would be appreciated it!
>>>
>>> Tony
>>>
>>>
>>> Martin Gainty wrote:
>>>
>>>> Tony-
>>>> More specifically you will need a
>>>> ApplicationMessageResources_en_US.property which would be located in 
>>>> web-inf\classes\tonyapp folder
>>>> where the property key value would display something like
>>>> userid=some_username
>>>> password=some_password
>>>> HTH,
>>>> Martin-
>>>> ----- Original Message ----- From: "Michael Jouravlev" 
>>>> <jm...@gmail.com>
>>>> To: "Struts Users Mailing List" <us...@struts.apache.org>
>>>> Sent: Wednesday, June 01, 2005 9:28 PM
>>>> Subject: Re: help with messages using bean on jsp
>>>>
>>>>
>>>> Do you have ApplicationMessageResources.properties property file,
>>>> which is located in WEB-INF\classes\tonyapp ?
>>>>
>>>> On 6/1/05, Tony Dahbura <to...@dahbura.com> wrote:
>>>>
>>>>> I have a peculiar problem cropping up with Struts 1.2.7...
>>>>>
>>>>> When I add an actionError to using my form bean and then go to display
>>>>> it in the html jsp page I get the following:
>>>>>
>>>>>     * ???en_US.userid is a required value.???
>>>>>     * ???en_US.password is a required value.???
>>>>>
>>>>> My struts-config.xml file looks like this for the message resources:
>>>>> <message-resources null="false"
>>>>> parameter="tonyapp.ApplicationMessageResources"/>
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>
> 

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


Re: help with messages using bean on jsp

Posted by Tony Dahbura <to...@dahbura.com>.
All:
Figured out the problem....:
My JSP page was trying to display the messages using the following code:
<ul>
    <html:messages id="errmsgs">
            <li><bean:message name="errmsgs"/></li>
     </html:messages>
</ul>

I should have used a <bean:write name="errmsgs"/>  tag instead.  I think 
the <bean:mesage> tag was trying to lookup the message as the key to a 
message rather than just displaying the message?

Thanks,
Tony


Martin Gainty wrote:

> Tony-
> to allow access by your Struts app's bean tag set the struts-config.xml
> <message-resources parameter=test.ApplicationResources"/>
> (ApplicationResources.properties is located in test folder off root)
> Now you can have multiple <message-resources with key="PropertyKey" to 
> identify the particular ApplicationResources implementation
>
> You can use bean:message to pull the parameter and substitute your 
> parameters in
> <bean:message key="label.welcome" arg0="Ralph" arg1="Nader"/>
>
> But JSTL is better suited for internationalisation and message 
> formatting so entering the bundle identifier in web.xml
> <context-param>
>  <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
>  <param-value>ApplicationResources</param-value>
> </context-param>
>
> later on in your jsp
> <%@ taglib uri=http://java.sun.com/jstl/fmt prefix="fmt"%>
> and now do your substitution..
> <fmt:message key="buttonsubmit" bundle="${bundleToUse}"/> where 
> bundleToUse is ApplicationResources.properties
> In this way all of your strings will be assigned to locale specific 
> properties file
>
> HTH,
> Martin-
> ----- Original Message ----- From: "Tony Dahbura" <to...@dahbura.com>
> To: "Martin Gainty" <mg...@hotmail.com>
> Cc: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Thursday, June 02, 2005 9:59 PM
> Subject: Re: help with messages using bean on jsp
>
>
>> I do not have a ApplicationMessageResources_en_US.properties but I do 
>> have a ApplicationMessageResources.properties file with the following 
>> properties:
>> global.required={0} is a required value.
>>
>> As can be seen the actual substitution is taking place.  I pass 
>> "userid" and it replaces the string with "userid is a required value"
>> so the substitution is working but the message is prepended with en_US
>>
>> Any help would be appreciated it!
>>
>> Tony
>>
>>
>> Martin Gainty wrote:
>>
>>> Tony-
>>> More specifically you will need a
>>> ApplicationMessageResources_en_US.property which would be located in 
>>> web-inf\classes\tonyapp folder
>>> where the property key value would display something like
>>> userid=some_username
>>> password=some_password
>>> HTH,
>>> Martin-
>>> ----- Original Message ----- From: "Michael Jouravlev" 
>>> <jm...@gmail.com>
>>> To: "Struts Users Mailing List" <us...@struts.apache.org>
>>> Sent: Wednesday, June 01, 2005 9:28 PM
>>> Subject: Re: help with messages using bean on jsp
>>>
>>>
>>> Do you have ApplicationMessageResources.properties property file,
>>> which is located in WEB-INF\classes\tonyapp ?
>>>
>>> On 6/1/05, Tony Dahbura <to...@dahbura.com> wrote:
>>>
>>>> I have a peculiar problem cropping up with Struts 1.2.7...
>>>>
>>>> When I add an actionError to using my form bean and then go to display
>>>> it in the html jsp page I get the following:
>>>>
>>>>     * ???en_US.userid is a required value.???
>>>>     * ???en_US.password is a required value.???
>>>>
>>>> My struts-config.xml file looks like this for the message resources:
>>>> <message-resources null="false"
>>>> parameter="tonyapp.ApplicationMessageResources"/>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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: help with messages using bean on jsp

Posted by Martin Gainty <mg...@hotmail.com>.
Tony-
to allow access by your Struts app's bean tag set the struts-config.xml
<message-resources parameter=test.ApplicationResources"/>
(ApplicationResources.properties is located in test folder off root)
Now you can have multiple <message-resources with key="PropertyKey" to 
identify the particular ApplicationResources implementation

You can use bean:message to pull the parameter and substitute your 
parameters in
<bean:message key="label.welcome" arg0="Ralph" arg1="Nader"/>

But JSTL is better suited for internationalisation and message formatting so 
entering the bundle identifier in web.xml
<context-param>
  <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
  <param-value>ApplicationResources</param-value>
</context-param>

later on in your jsp
<%@ taglib uri=http://java.sun.com/jstl/fmt prefix="fmt"%>
and now do your substitution..
<fmt:message key="buttonsubmit" bundle="${bundleToUse}"/> where bundleToUse 
is ApplicationResources.properties
In this way all of your strings will be assigned to locale specific 
properties file

HTH,
Martin-
----- Original Message ----- 
From: "Tony Dahbura" <to...@dahbura.com>
To: "Martin Gainty" <mg...@hotmail.com>
Cc: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Thursday, June 02, 2005 9:59 PM
Subject: Re: help with messages using bean on jsp


>I do not have a ApplicationMessageResources_en_US.properties but I do have 
>a ApplicationMessageResources.properties file with the following 
>properties:
> global.required={0} is a required value.
>
> As can be seen the actual substitution is taking place.  I pass "userid" 
> and it replaces the string with "userid is a required value"
> so the substitution is working but the message is prepended with en_US
>
> Any help would be appreciated it!
>
> Tony
>
>
> Martin Gainty wrote:
>
>> Tony-
>> More specifically you will need a
>> ApplicationMessageResources_en_US.property which would be located in 
>> web-inf\classes\tonyapp folder
>> where the property key value would display something like
>> userid=some_username
>> password=some_password
>> HTH,
>> Martin-
>> ----- Original Message ----- From: "Michael Jouravlev" <jm...@gmail.com>
>> To: "Struts Users Mailing List" <us...@struts.apache.org>
>> Sent: Wednesday, June 01, 2005 9:28 PM
>> Subject: Re: help with messages using bean on jsp
>>
>>
>> Do you have ApplicationMessageResources.properties property file,
>> which is located in WEB-INF\classes\tonyapp ?
>>
>> On 6/1/05, Tony Dahbura <to...@dahbura.com> wrote:
>>
>>> I have a peculiar problem cropping up with Struts 1.2.7...
>>>
>>> When I add an actionError to using my form bean and then go to display
>>> it in the html jsp page I get the following:
>>>
>>>     * ???en_US.userid is a required value.???
>>>     * ???en_US.password is a required value.???
>>>
>>> My struts-config.xml file looks like this for the message resources:
>>> <message-resources null="false"
>>> parameter="tonyapp.ApplicationMessageResources"/>
>>
>>
>> ---------------------------------------------------------------------
>> 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: help with messages using bean on jsp

Posted by Tony Dahbura <to...@dahbura.com>.
I do not have a ApplicationMessageResources_en_US.properties but I do 
have a ApplicationMessageResources.properties file with the following 
properties:
global.required={0} is a required value.

As can be seen the actual substitution is taking place.  I pass "userid" 
and it replaces the string with "userid is a required value"
so the substitution is working but the message is prepended with en_US

Any help would be appreciated it!

Tony


Martin Gainty wrote:

> Tony-
> More specifically you will need a
> ApplicationMessageResources_en_US.property which would be located in 
> web-inf\classes\tonyapp folder
> where the property key value would display something like
> userid=some_username
> password=some_password
> HTH,
> Martin-
> ----- Original Message ----- From: "Michael Jouravlev" <jm...@gmail.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Wednesday, June 01, 2005 9:28 PM
> Subject: Re: help with messages using bean on jsp
>
>
> Do you have ApplicationMessageResources.properties property file,
> which is located in WEB-INF\classes\tonyapp ?
>
> On 6/1/05, Tony Dahbura <to...@dahbura.com> wrote:
>
>> I have a peculiar problem cropping up with Struts 1.2.7...
>>
>> When I add an actionError to using my form bean and then go to display
>> it in the html jsp page I get the following:
>>
>>     * ???en_US.userid is a required value.???
>>     * ???en_US.password is a required value.???
>>
>> My struts-config.xml file looks like this for the message resources:
>> <message-resources null="false"
>> parameter="tonyapp.ApplicationMessageResources"/>
>
>
> ---------------------------------------------------------------------
> 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: help with messages using bean on jsp

Posted by Martin Gainty <mg...@hotmail.com>.
Tony-
More specifically you will need a
ApplicationMessageResources_en_US.property which would be located in 
web-inf\classes\tonyapp folder
where the property key value would display something like
userid=some_username
password=some_password
HTH,
Martin-
----- Original Message ----- 
From: "Michael Jouravlev" <jm...@gmail.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Wednesday, June 01, 2005 9:28 PM
Subject: Re: help with messages using bean on jsp


Do you have ApplicationMessageResources.properties property file,
which is located in WEB-INF\classes\tonyapp ?

On 6/1/05, Tony Dahbura <to...@dahbura.com> wrote:
> I have a peculiar problem cropping up with Struts 1.2.7...
>
> When I add an actionError to using my form bean and then go to display
> it in the html jsp page I get the following:
>
>     * ???en_US.userid is a required value.???
>     * ???en_US.password is a required value.???
>
> My struts-config.xml file looks like this for the message resources:
> <message-resources null="false"
> parameter="tonyapp.ApplicationMessageResources"/>

---------------------------------------------------------------------
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: help with messages using bean on jsp

Posted by Michael Jouravlev <jm...@gmail.com>.
Do you have ApplicationMessageResources.properties property file,
which is located in WEB-INF\classes\tonyapp ?

On 6/1/05, Tony Dahbura <to...@dahbura.com> wrote:
> I have a peculiar problem cropping up with Struts 1.2.7...
> 
> When I add an actionError to using my form bean and then go to display
> it in the html jsp page I get the following:
> 
>     * ???en_US.userid is a required value.???
>     * ???en_US.password is a required value.???
> 
> My struts-config.xml file looks like this for the message resources:
> <message-resources null="false"
> parameter="tonyapp.ApplicationMessageResources"/>

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


Re: help with messages using bean on jsp

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
This does look strange - its almost as if the message has been resolved
twice and the second time it can't find "userid is a required value" as a
key and so formatting it in the standard "???localeKey.messageKey???" format

I don't have time to help you - I'm away now for a few days, but the only
thing I can suggest is to turn logging on in "TRACE" mode for
PropertyMessagesResources - it outputs quite a bit of debugging info, which
might shed more light on this.

On your bean:write problem, it would be helpful to include any exception
from the logs.

Also was your app working OK in the same environment using Struts 1.2.6 or
Struts 1.2.4?

Niall

----- Original Message ----- 
From: "Tony Dahbura" <to...@dahbura.com>
Sent: Thursday, June 02, 2005 2:08 AM


> I have a peculiar problem cropping up with Struts 1.2.7...
>
> When I add an actionError to using my form bean and then go to display
> it in the html jsp page I get the following:
>
>     * ???en_US.userid is a required value.???
>     * ???en_US.password is a required value.???
>
> My struts-config.xml file looks like this for the message resources:
> <message-resources null="false"
> parameter="tonyapp.ApplicationMessageResources"/>
>
> If I turn the null to true I get nothing rendered-the
> ApplicationMessageResources file is in the proper location and moving it
> results in the message not being displayed (as a test).  The HTML
> elements that are attempting to output the values are:
> <logic:messagesPresent>
>           <ul>
>                 <html:messages id="errmsgs">
>                       <li><bean:message name="errmsgs"/></li>
>                 </html:messages>
>            </ul>
>  </logic:messagesPresent>
>
> And finally the loginForm java code that is doing this is at:
>  if (getUsername() == null || getUsername().length() < 1) {
>             errors.add( ActionMessages.GLOBAL_MESSAGE, new
> ActionMessage("global.required", "userid" ) );
>  }
>  if (getPassword() == null || getPassword().length() < 1) {
>             errors.add( ActionMessages.GLOBAL_MESSAGE, new
> ActionMessage("global.required", "password") );
>   }
>
> The properties file looks like this:
> global.required={0} is a required value.
>
> I am developing with Eclipse and using tomcat 5.5 with jdk 1.5.  This is
> baffling to me as to why it is prepending the en_US to the value of the
> key after it looks it up.  I actually get the message and the
> substitution but somehow the en_US gets put in and it flags an error
> that it cannot find the message (indicated by the ???).
>
> On another note I have had quite a bit of difficulty using the
> bean:write tags with bean properties that do not return Strings...Some
> of my beans return integers and the bean:write tag just fails and causes
> the rest of the page after the failure to not even render....Not sure if
> it is something with this particular library or not..
>
> Any help would be very appreciated.  I looked through the release notes
> on the new struts 1.2.7 and did not see any fixes....



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