Showing messages after a redirect

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Showing messages after a redirect

Dimitris Mouchritsas-3
Hi all,
I've got the following problem. I have an action that edits the details
of a user.
When the action finishes correctly I want to show a confirmation
message, so in the action:

ActionMessages msg = new ActionMessages();
msg.add(Constants.MESSAGE_CONFIRM, new
ActionMessage("prompt.changes.saved"));
saveMessages(request, msg);

But when I'm redirected back in the jsp there's no message showing
(there's a specific tile for
messages). Can you please advise on how I can accomplish this?

Thank you
Dimitris



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Showing messages after a redirect

Antonio Petrelli-3
2008/7/1 Dimitris Mouchritsas <[hidden email]>:
> ActionMessages msg = new ActionMessages();
> msg.add(Constants.MESSAGE_CONFIRM, new
> ActionMessage("prompt.changes.saved"));
> saveMessages(request, msg);
>
> But when I'm redirected back in the jsp there's no message showing (there's
> a specific tile for
> messages).

Heh, that's a good one: I think it is not possible to use
ActionMessages, since they remain active only in the current request.
When you redirect you are in fact creating a new request, and the
messages will disappear.
Other frameworks, like Struts 2, have a "flash" scope, that is
available just the time of one single redirect. It works by putting
temporarily objects in session and then putting them back in request
after the redirect.
You could put these messages in session and use a filter (to .jsp
files) to put them back to request.
Or you can take a look at the "click" scope of Scopes:
http://scopes.sourceforge.net/documentation/more-scopes/click-scope.html

Antonio

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Showing messages after a redirect

Ian Roughley
Have you looked at the message store interceptor?

/ian

Antonio Petrelli wrote:

> 2008/7/1 Dimitris Mouchritsas <[hidden email]>:
>  
>> ActionMessages msg = new ActionMessages();
>> msg.add(Constants.MESSAGE_CONFIRM, new
>> ActionMessage("prompt.changes.saved"));
>> saveMessages(request, msg);
>>
>> But when I'm redirected back in the jsp there's no message showing (there's
>> a specific tile for
>> messages).
>>    
>
> Heh, that's a good one: I think it is not possible to use
> ActionMessages, since they remain active only in the current request.
> When you redirect you are in fact creating a new request, and the
> messages will disappear.
> Other frameworks, like Struts 2, have a "flash" scope, that is
> available just the time of one single redirect. It works by putting
> temporarily objects in session and then putting them back in request
> after the redirect.
> You could put these messages in session and use a filter (to .jsp
> files) to put them back to request.
> Or you can take a look at the "click" scope of Scopes:
> http://scopes.sourceforge.net/documentation/more-scopes/click-scope.html
>
> Antonio
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Showing messages after a redirect

Antonio Petrelli-3
2008/7/1 Ian Roughley <[hidden email]>:
> Have you looked at the message store interceptor?

For Struts 1?

Antonio

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Showing messages after a redirect

Ian Roughley
my mistake, only saw the last message.

Antonio Petrelli wrote:

> 2008/7/1 Ian Roughley <[hidden email]>:
>  
>> Have you looked at the message store interceptor?
>>    
>
> For Struts 1?
>
> Antonio
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Showing messages after a redirect

Dimitris Mouchritsas-3
Ian Roughley wrote:

> my mistake, only saw the last message.
>
> Antonio Petrelli wrote:
>> 2008/7/1 Ian Roughley <[hidden email]>:
>>  
>>> Have you looked at the message store interceptor?
>>>    
>>
>> For Struts 1?
>>
>> Antonio
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>  
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
Yes, for Struts 1.3.8, sorry I forgot to mention. Actually what I did
(but it's more or less
specific for the action) is to just forward, not redirect. But I've got
another question now?
Is there a way I can pass a parameter in the request? I need to pass an
id for an Account
when I go back to the Prepare action. But since I'm not manipulating the
url?....

Dimitris

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Showing messages after a redirect

Adam Hardy (struts)
Dimitris Mouchritsas on 01/07/08 16:50, wrote:
> Ian Roughley wrote: Yes, for Struts 1.3.8, sorry I forgot to mention.
> Actually what I did (but it's more or less specific for the action) is to
> just forward, not redirect. But I've got another question now? Is there a way
> I can pass a parameter in the request? I need to pass an id for an Account
> when I go back to the Prepare action. But since I'm not manipulating the
> url?....


actually you can put the messages collection into the session if you're ok to
manage it yourself.

session.setAttribute(Globals.MESSAGE_KEY, messages);

and then in the next action redirected to:

ActionMessages messages = new ActionMessages((ActionMessages)
                request.getAttribute(Globals.MESSAGE_KEY));
messages.add((ActionMessages)
                session.getAttribute(Globals.MESSAGE_KEY));


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Showing messages after a redirect

Adam Hardy (struts)
In reply to this post by Dimitris Mouchritsas-3
Dimitris Mouchritsas on 01/07/08 16:50, wrote:
>>
> Yes, for Struts 1.3.8, sorry I forgot to mention. Actually what I did (but
> it's more or less specific for the action) is to just forward, not redirect.
> But I've got another question now? Is there a way I can pass a parameter in
> the request? I need to pass an id for an Account when I go back to the
> Prepare action. But since I'm not manipulating the url?....

And you can pass a parameter in the request if you built a new Forward based on
the one you want and construct the URL manually. I dug this out of an old app:

forward = mapping.findForward(origForward);
forwardName = forward.getName();
redirect = forward.getRedirect();
//change URL if different URL given
forwardUrl = "/somewhere/else";
forwardUrl += "?" + customQueryString;
forward = new ActionForward(forwardName, forwardUrl,
     redirect);



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Showing messages after a redirect

Dimitris Mouchritsas-3
Adam Hardy wrote:

> Dimitris Mouchritsas on 01/07/08 16:50, wrote:
>>>
>> Yes, for Struts 1.3.8, sorry I forgot to mention. Actually what I did
>> (but
>> it's more or less specific for the action) is to just forward, not
>> redirect.
>> But I've got another question now? Is there a way I can pass a
>> parameter in
>> the request? I need to pass an id for an Account when I go back to the
>> Prepare action. But since I'm not manipulating the url?....
>
> And you can pass a parameter in the request if you built a new Forward
> based on the one you want and construct the URL manually. I dug this
> out of an old app:
>
> forward = mapping.findForward(origForward);
> forwardName = forward.getName();
> redirect = forward.getRedirect();
> //change URL if different URL given
> forwardUrl = "/somewhere/else";
> forwardUrl += "?" + customQueryString;
> forward = new ActionForward(forwardName, forwardUrl,
>     redirect);
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
Aaah, great; that seems to solve both of my problems :)
Thank you
Dimitris

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

How to get Web Application path at Run-Time

Aggarwal, Rajat
Hi All,

 

I am developing a web application using the struts 2 framework. In one
of the actions, I need to create a file at the run-time at a particular
location relative to the path where my web-application is deployed. How
can I retrieve the path at which my Web-app is deployed at run-time in
my action class?

 

An early response shall be appreciated

 

Thanks and regards

 

Rajat Aggarwal

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to get Web Application path at Run-Time

Paweł Wielgus
Hi,
for example:
filterConfig.getServletContext().getRealPath("")
in FilterDispatcher.init(...) method.

Best greetings,
Paweł Wilegus.

On 02/07/2008, Aggarwal, Rajat <[hidden email]> wrote:

> Hi All,
>
>
>
>  I am developing a web application using the struts 2 framework. In one
>  of the actions, I need to create a file at the run-time at a particular
>  location relative to the path where my web-application is deployed. How
>  can I retrieve the path at which my Web-app is deployed at run-time in
>  my action class?
>
>
>
>  An early response shall be appreciated
>
>
>
>  Thanks and regards
>
>
>
>  Rajat Aggarwal
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: [hidden email]
>  For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: How to get Web Application path at Run-Time

Łukasz Lenart
In reply to this post by Aggarwal, Rajat
> I am developing a web application using the struts 2 framework. In one
> of the actions, I need to create a file at the run-time at a particular
> location relative to the path where my web-application is deployed. How
> can I retrieve the path at which my Web-app is deployed at run-time in
> my action class?

You can implement in action ServletContextAware interface [1], you
will get access to ServletContext then you have getRealPath(String)

[1] http://struts.apache.org/2.1.2/struts2-core/apidocs/org/apache/struts2/util/ServletContextAware.html


Regards
--
Lukasz
http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Struts2 file upload and div contol in same form

Saqib Shehzad
Hi,

I am trying to use ajax div and file control in same form. But div is not
loading properly instead it shows [object HTMLDocument] on firefox and
[object] on IE. But if I try to use them separately then both are working
fine. Anyone has has any idea what is happening ??? Here is the code
/***************************************************************************
**********************************


<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
 <%@ taglib prefix="s" uri="/struts-tags" %>
 <html>
 <head>
 <s:head theme="ajax" />
 <link href="<s:url value="/css/campaign.css"/>" rel="stylesheet"
   type="text/css"/>
     <title>upload and ajax test</title>
 </head>
 <script>
  function changeApplication()
  {
        dojo.event.topic.publish("change_Application");
  }
  </script>
 <body>
 <s:url id="updateSecondList" action="updateSecondList" />
   
    <s:actionerror />
    <s:fielderror />
     <s:form id="test_form" name="test_form" action="FileAction"
method="POST" theme="ajax" enctype="multipart/form-data">
     
         <s:select
             label="First List"
            list="firstList"
            name="selectedItem"
            onchange="javascript:changeApplication();return false;">
        </s:select>
       
        <tr>
        <td class="tdLabel"><label class="label">Second List</label></td>
        <td>
        <s:div showLoadingText="false"
             id="details" href="%{updateSecondList}" theme="ajax"
             listenTopics="change_Application" formId="test_form">
         </s:div>                          
        </td>
        </tr>
       
        <s:file name="upload" label="File"/>
        <s:submit />
     </s:form>
 </body>
 </html>
/***************************************************************************
******************************/
Regards


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Showing messages after a redirect

pdegregorio
In reply to this post by Adam Hardy (struts)
Adam Hardy (struts) wrote
Dimitris Mouchritsas on 01/07/08 16:50, wrote:

actually you can put the messages collection into the session if you're ok to
manage it yourself.

session.setAttribute(Globals.MESSAGE_KEY, messages);

and then in the next action redirected to:

ActionMessages messages = new ActionMessages((ActionMessages)
                request.getAttribute(Globals.MESSAGE_KEY));
messages.add((ActionMessages)
                session.getAttribute(Globals.MESSAGE_KEY));
Thank you. This worked for me when I added the following line to the 2nd block of code (the next action redirected to)

saveMessages(request, messages);