This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "need a help on Struts ActionMessage " Watch "need a help on Struts ActionMessage " New topic
Author

need a help on Struts ActionMessage

sandeep Mule
Greenhorn

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-------
Try{
//Action Specific code.

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

errors.add("ErrorMessage",actionMessage);
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();
while(it.hasNext()){
System.out.println(" Item == "+it.next());
}
forward = mapping.findForward("failure");


Struts Entry for Action and message is as given below.


<form-bean name="UserForm" type="com.lb.ort.web.form.UserForm" />



<action path="/UserAction"
type="com.lb.ort.web.action.UserAction" name="UserForm"
input="/index.jsp" parameter="parameter"
scope="request">
<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" />
</action>


<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.UserForm.action.Problem={0}Sandeep
error.field.required=Value Required at given spot.


And My JSP is



<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>

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

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.


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need a help on Struts ActionMessage