struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kedgecomb <kevinedgec...@yahoo.com>
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 {
		service.addUser(user);
		users = service.getAllUsers();
    		
    	} catch(PersistenceExistsException ee) {
    		addActionError(getText("user.alreadyExists"));
    		return Action.INPUT;
    		
    	} catch(PersistenceNotFoundException nfe) {
        	this.addActionError(getText("global.unableToProcessRequest"));
    		return Action.INPUT;
    	}
	addActionMessage(getText("user.addSuccess"));
        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:

<tr>
	<td colspan="2">
		<s:div id="users" theme="ajax" href="userAdmin.do" listenTopics="delete"
>loading...</s:div>
	</td>
</tr>

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:

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

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:url>
<s:a href="%{removeUrl}" theme="ajax" notifyTopics="delete" ><s:text
name="global.delete"/></s:a>

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: http://www.nabble.com/Mixing-Struts2-ajax-functions-with-actionErrors-and-actionMessages-tf3222408.html#a8950048
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message