File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes need a help on Struts ActionMessage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "need a help on Struts ActionMessage " Watch "need a help on Struts ActionMessage " New topic

need a help on Struts ActionMessage

sandeep Mule

Joined: Jul 31, 2007
Posts: 1
I need a help on Struts ActionMessage class.
I am using ActionMessages to Show Errors collected in processing Action class.
I am unable to get the messages displayed in my JSP. Even messages are present in ActionErrors Object, JSP shows Blank space instead of message. Can some buddy look into my problem.

Code in my action is like-------
//Action Specific code.

} catch(ExecuteOperationException eoe){
ActionMessage actionMessage = new ActionMessage("error.UserForm.LastName.NotPresent",false);

System.out.println("Key = "+actionMessage.getKey()+" /n Value = "+actionMessage.getValues()+" /n isResource = "+actionMessage.isResource());
saveErrors(request, errors);

System.out.println("Error = "+ errors);
Iterator it = errors.get();
System.out.println(" Item == ";
forward = mapping.findForward("failure");

Struts Entry for Action and message is as given below.

<form-bean name="UserForm" type="" />

<action path="/UserAction"
type="" name="UserForm"
input="/index.jsp" parameter="parameter"
<forward name="add" path="/pages/AddUser.jsp" />
<forward name="edit" path="/pages/EditUsre.jsp" />
<forward name="search" path="/pages/DeleteUser.jsp" />
<forward name="failure" path="/pages/AddUser.jsp" />

<message-resources key="error"
parameter="com/lb/ort/web/resources/ErrorMessages" null="false" />

also my message Resource file is

error.UserForm.FirstName.NotPresent=Please insert value for First Name.
error.UserForm.LastName.NotPresent=Please insert value for Last Name.
error.field.required=Value Required at given spot.

And My JSP is

<%@ taglib uri="" prefix="html"%>
<%@ taglib uri="" prefix="logic"%>

<script language="javascript">
<html:messages id="msg" property="ErrorMessage" bundle="error">
paintErrorMessage('<bean:write name="msg"/>');

Can Someone try to Solve my problem.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
There are a couple of things I noticed:

1- Your logic:messagesPresent tag has an invalid character in it. Make sure it reads logic:messagesPresent.

2- You should either include property="ErrorMessage" in both the logic:messagesPresent and the html:messages tag, or remove it from both.

3- There is a possiblity that there's something wrong with your paintErrorMessage() function. I'd try just displaying the errors normally first and then try it with your function just to see if that's the problem.

Consultant, Sima Solutions
I agree. Here's the link:
subject: need a help on Struts ActionMessage
It's not a secret anymore!