Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

need a help on Struts ActionMessage  RSS feed

sandeep Mule
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!