Thanks for the feedback Martin.

This is a really generic issue to me.
I have a list.  From the list you can do operations.  When you complete the 
operation you want to go back to the list.
Success or error, you want to go the list with a message from the first 
dispatch.

Another example would be having a [delete] link on each row of the list.
You click [delete], it fails because the page was stale, so delegate to the 
list() dispatch with the error message from delete().

I am asking for a best practice because I can make this work in several ways, 
none of which seem clean.
This seems like the default behavior of any list page to me.  I am hoping there 
is a prescribed flow to follow.

There are a couple options that I can think of:

1) go to error.jsp
This is really not desired.
Going to a default error page (or even a custom one) is breaking the workflow 
of the user.
They see the error and next need to click back to the list so they can try 
again.

2) call list() as the return import().
This works fine, but now there is hard coded "chaining" logic.

3) pass my own parameter in the result action tag in struts.xml.
Ex. <param name="myErrorMessage">${myErrorMessage}</param>
This is not desired either.  It basically means I am replacing the existing 
error framework.
All my JSPs would need to look for myErrorMessage instead of using the built in 
tags.


-----Original Message-----
From: Martin Gainty [mailto:[EMAIL PROTECTED]
Sent: Tuesday, August 12, 2008 2:20 PM
To: Struts Users Mailing List
Subject: RE: Best practice for passing success/error message to another 
dispatch (struts2)?


your action execute method can return "error" result which maps to error page 
e.g.
<result name="error">/error.jsp</result>

where error looks like
<html>
<body>
<b>YOU have an error !</b>
</body>
</html>

better to create a div tag and write a meaningful error to response which 
displays response in div tag ...
http://cwiki.apache.org/WW/ajax-recipes.html

Anyone else?
Martin
______________________________________________
Disclaimer and confidentiality note
Everything in this e-mail and any attachments relates to the official business 
of Sender. This transmission is of a confidential nature and Sender does not 
endorse distribution to any party other than intended recipient. Sender does 
not necessarily endorse content contained within this transmission.


> From: [EMAIL PROTECTED]
> To: user@struts.apache.org
> Date: Tue, 12 Aug 2008 15:05:42 -0400
> Subject: Best practice for passing success/error message to another dispatch 
> (struts2)?
>
> I have an action with two dispatch methods.
> I have a single JSP that renders a list and also have an import file field.
> On import failure, I want to populate the list with an error message.
>
> THE PROBLEM:
> It looks like validation for the list() method is wiping the errors from the 
> import() method.
>
> Example struts.xml:
>     <action name="*Role" class="RoleAction" method="list">
>       <result name="input">/list.page</result>
>       <result name="success">/list.page</result>
>     </action>
>
>     <action name="importRole" class="RoleAction" method="import">
>       <result name="input" type="chain">listRole</result>
>       <result name="success" type="chain">listRole</result>
>     </action>
>
> Example pseudo code:
> public String list() {
>   // sql lookup, populate list
>   return "success";
> }
>
> public String import() {
>   // do import
>   If (fail) {
>     addActionError(errorMessage);
>   }
>   return "success";
> }
>
>
>

_________________________________________________________________
Got Game? Win Prizes in the Windows Live Hotmail Mobile Summer Games Trivia 
Contest
http://www.gowindowslive.com/summergames?ocid=TXT_TAGHM

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to