jQuery in Action, 2nd edition*
The moose likes Struts and the fly likes ActionMessage is not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "ActionMessage is not working " Watch "ActionMessage is not working " New topic
Author

ActionMessage is not working

selvi family
Ranch Hand

Joined: Nov 26, 2004
Posts: 39
Hi,

This is my execute() method in Action class.

public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
{
UseMeBean ub=new UseMeBean();
request.setAttribute("ubean",ub);
System.out.println("Inside Use action");
boolean flag = ub.doCheck(request);
ActionMessages messages = new ActionMessages();
if(flag)
{
ActionMessage msg = new ActionMessage("message1", "data.use");
messages.add(ActionMessages.GLOBAL_MESSAGE, msg);
System.out.println("Inside Use Action if " +messages);
saveMessages(request,messages);
return mapping.findForward("use");
}
else
{
ActionMessage msg = new ActionMessage("message1", "data.no");
messages.add(ActionMessages.GLOBAL_MESSAGE, msg);
System.out.println("Inside Use Action else " +messages);
saveMessages(request,messages);
return mapping.findForward("nouse");
}

to get the value of the message i used <html:messages> in my forward JSP either Use.jsp or NoUse.jsp

this is the code:
<html:messages id="msg" message="true">
<bean:write name="msg"/>

But no message is displayed...

Other text in JSPs are displayed properly except the message.

In my ApplicationResources.properties I gave entry like

data.use=<p class="body">Using Message is Successful</p>
data.no=<p class="body">Using Message is NOT Successful</p>

I am able to use other resources specified in ApplicationResources .So its not a problem with ApplicationResources.

Problem is with <html:messages> tag or in my Action class..
pls tell me where I went wrong...
Cendy Nguvy
Ranch Hand

Joined: May 25, 2005
Posts: 37
Hi,

Try this :
in Action class

in jsp

And verify scope="request" for action in struts-config.xml.
I hope its working.
Cendy
[ July 01, 2005: Message edited by: cendy nguvy ]
selvi family
Ranch Hand

Joined: Nov 26, 2004
Posts: 39
Hi Cendy,

I tried this but its not working...I dont get ActionMessage in my JSP.

code in Action Class:

ActionMessage msg = new ActionMessage("data.use");
messages.add("message1", msg);
saveMessages(request,messages);
return mapping.findForward("use");

In JSP:
<html:messages id="message1" message="true">
<bean:write name="message1"/>
</html:messages>

In struts-config.xml:
<action name="useForm" path="/use" type="myTest.struts.UseAction" scope="request">

<forward name="use" path="/Use.jsp" />
<forward name="nouse" path="/NoUse.jsp" />

</action>

plese help me....
Cendy Nguvy
Ranch Hand

Joined: May 25, 2005
Posts: 37
Hi,

I don't understand why its not working.
Could you try to code saveMessages(session,messages) in your Action class and scope="session" in struts-config ?
Tell me if its working better.

Cendy
[ July 02, 2005: Message edited by: cendy nguvy ]
selvi family
Ranch Hand

Joined: Nov 26, 2004
Posts: 39
hi ,

I tried HttpSession with saveMessages()

saveMessages(HttpSession session,messages);

I got 2 errors while compiling the Action Class.
myTest/struts/UseAction.java:30: ')' expected
saveMessages(HttpSession session,messages);
^
myTest/struts/UseAction.java:30: cannot resolve symbol
symbol : variable HttpSession
location: class myTest.struts.UseAction
saveMessages(HttpSession session,messages);


^
I have included

import javax.servlet.http.HttpSession;

still got the above error..Not able to compile Action class ..

pls tell me what could be the problem...
Cendy Nguvy
Ranch Hand

Joined: May 25, 2005
Posts: 37
Hi,

Code this in your Action class :

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ActionMessage is not working