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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Displaying Error Messages

Status
Not open for further replies.

allanon2

Programmer
Mar 13, 2002
43
CA
I am trying to display error messages and the are displaying but not correctly. They display like this:

???en_US.Invalid userId or Password???

Here is the code that I use to fill the errors:

<code>
public class BaseAction extends Action {

public static final String APP_WARNING_KEY = "APP_WARNING_KEY";
public static final String APP_ERROR_KEY = "APP_ERROR_KEY";

protected void saveAppWarnings(HttpServletRequest request, ActionMessages messages) {
saveAppMessages(request, messages, APP_WARNING_KEY);
}

protected void saveAppErrors(HttpServletRequest request, ActionMessages messages) {
saveAppMessages(request, messages, APP_ERROR_KEY);
}

private void saveAppMessages(HttpServletRequest request, ActionMessages messages, String key) {
// Remove any messages attribute if none are required
if ((messages == null) || messages.isEmpty()) {
request.removeAttribute(key);
return;
}

// Save the messages we need
request.setAttribute(key, messages);
}
</code>

And here is the code that I use to display the messages:

<code>
<logic:messagesPresent name="APP_ERROR_KEY">
<table border="1" bgcolor="orange" width="100%" align="center"><tr><td>
<p>
<img src="images/icon-alert.gif" border="0" vspace="2" hspace="10" align="center">
<bean:message bundle="errors" key="ERRORS_HEADING"/>
</p>
<ul>
<html:messages id="error" name="APP_ERROR_KEY">
<li><bean:write name="error"/></li>
</html:messages>
</ul>
</td></tr></table>
<p>
</logic:messagesPresent>
<logic:messagesPresent name="APP_WARNING_KEY">
<table border="1" bgcolor="yellow" width="100%" align="center"><tr><td>
<p>
<img src="images/icon-warning.gif" border="0" vspace="2" hspace="10" align="center">
<bean:message key="warnings.heading"/>
</p>
<ul>
<html:messages id="error" name="APP_WARNING_KEY">
<li><bean:write name="error"/></li>
</html:messages>
</ul>
</td></tr></table>
<p>
</logic:messagesPresent>
</code>

Can anyone suggest what it is theat my messages are looking for and how I can get rid of the "???en_US."?
 
Code:
 and
not <> </>


en_US.Invalid

Taking a guess, I would say that your locale variable is set to true and it's looking application.resources for en_US.Invalid.

Can't help you on the rest, I use <html:errors/> It's faster and easier although less robust.

HtH

Andrew
 
Thanks for the help. I turned it off using

<controller locale="false"/>

but no luck. Still does the same thing.
 
<bean:message bundle="errors" key="ERRORS_HEADING"/>

This is the only thing I don't follow. Where is the constant ERRORS_HEADING set?
 
If you put this line of code:

<message-resources parameter="ErrorMessages" key="errors" null="false"/>

into the struts-config.xml file it sets up a pointer to a message file called ErrorMessages.properties

In this file I only have two line right now cause I cant get thigs to work quite right. The two lines are:

ERROR_KEY=Unknown Error
ERRORS_HEADING=ERROR - The follwoing serious errors need to be corrected.

What that line of code:

<bean:message bundle="errors" key="ERRORS_HEADING"/>

does is print out the message:

ERROR - The follwoing serious errors need to be corrected.

The limitation of this is that that particular line only works for messages stored in a message file. This of course is not useful for generated messages.

This part currently is working with no problem.

It is just the line:

<li><bean:write name="error"/></li>

that does the strange stuff. It still produses my messages but not correctly.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top