Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with html:messages tag

Status
Not open for further replies.

foxalert

Programmer
Jul 17, 2005
3
FR
I get this: "Cannot find bean msg in any scope" with the following code in my jsp page:

<logic:messagesPresent message="true">
there are messages:<br>
<ul>
<html:messages id="msg" message="true">
<li><bean:write name="msg" /></li>
</html:messages>
</ul>
</logic:messagesPresent>

I know there are some messages to display (if I suppress the 'bean:write' block, I get the header 'there are messages:'). But no 'msg' bean has been created inside the loop. Any tips please ?
 
what happens when you take message="true" out?

message By default the tag will retrieve the bean it will iterate over from the Globals.ERROR_KEY constant string, but if this attribute is set to 'true' the bean will be retrieved from the Globals.MESSAGE_KEY constant string. Also if this is set to 'true', any value assigned to the name attribute will be ignored.

name Name of the bean in any scope under which our messages have been stored. If not present, the name specified by the Globals.ERROR_KEY constant string will be used. [RT Expr]

I think if you use message="true" you have to use name=" "

But test it out and see what happens.

HTH

Andrew
 
Thanks for your reply Rhon.

I have tried without message="true" and I get the same error. In fact, it was predictable because I had put message="true" also in <logic:messagesPresent message="true">. As i enter this loop, I am pretty sure that real messages (with key Globals.MESSAGE_KEY) are present and can be displayed.

I had populated the messages in different ways to understand what happens. The last way is some jsp code before going to the <logic:messagePresent...>:

<%
ActionMessages messages=new ActionMessages();
messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message A"));
messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message B"));
messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message C"));
request.setAttribute(Globals.MESSAGE_KEY, messages);

%>

I know I pass 3 times through the loop (I can check it by replacing the message display by a hard coded string display). But the 'msg' bean is not set as it should be in <html:messages id="msg" message="true">.

Fox
 
I'm at a loss, unless there is some way to set the GLOBAL_KEY somewhere... perhaps in the application.resource file?

Check out Ted Husted's page:

Try Tip #17 and see if that works for you and move on from there?

The only other thing I can think of is you're using Tiles and the information is in two different tiles which are natrually seperated when it comes to sharing resources (Tile 1 doesn't have access to information in Tile 2 by default).

Sorry I couldn't be of any further service,

The only other thing I could suggest is searching the Struts mail archive:
or join it itself:
But if this is an answered question already they're first suggestion will be to search the archives.

Best of Luck

Andrew
 
Thanks again for your reply. I found valuable information especially at
I eventually found the issue origin. It comes from a silly misunderstanding on message nature. What you put in a message is only a key. If you have no entry for this key in the resources bundle, the result is 'null' in msg. That was the error I got: using bean:write on a null bean.

Be patient for beginners :)
Fox
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top