struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kedgecomb <>
Subject Mixing Struts2 ajax functions with actionErrors and actionMessages
Date Tue, 13 Feb 2007 18:28:39 GMT

I have been using the actionErrors and actionMessage features of Struts2 for
some time and they have worked well for providing user feedback, (e.g.;
"Business Center deleted successfully", "User already exists with this ID",
etc.).  I add the error or the message in the action class like so:

    public String add() throws Exception {
    	try {
		users = service.getAllUsers();
    	} catch(PersistenceExistsException ee) {
    		return Action.INPUT;
    	} catch(PersistenceNotFoundException nfe) {
    		return Action.INPUT;
        return SUCCESS;

This had the effect of deleting a user, refreshing the list of all users,
and sending a success message if all went well.
If something went wrong, a descriptive error would be displayed just above
the list of users.

It worked well until I began to incorporate the AJAX tags into the mix.  I
use a s:div to display the list of users:

	<td colspan="2">
		<s:div id="users" theme="ajax" href="" listenTopics="delete"

The JSP fragment that is returned to this div contains the list of users. 
This also worked well.  But the JSP also contains the actionError and
actionMessage tags:

	<td colspan="4" class="PageStatus">
		<font color="#FF0000"><s:actionerror/></font>
	<td colspan="4" class="PageStatus">
		<font color="#00FF00"><s:actionmessage/></font>

The problem is that these tags are never populated while using the AJAX
feature.  Neither errors nor messages are displayed at any time.  If I use
the same url that the s:div tag uses, and key it into the browser address,
the row is added or deleted and the message displays correctly, (using the
exact same jsp).  When I use an ajax link:

<s:url id="removeUrl" action="removeUser">
	<s:param name="userId" value="userId" />
<s:a href="%{removeUrl}" theme="ajax" notifyTopics="delete" ><s:text

the correct user is deleted, the div is refreshed with the new list of
users, but no message displays.

Are the message tags handled differently when using AJAX?

View this message in context:
Sent from the Struts - User mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message