You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Srinivas Surapaneni <sr...@gmail.com> on 2008/02/15 21:20:26 UTC

struts result going to a current page

I want to define a global exception handler where if this exception happens,
it goes to the current page

Is there any way to get the current page and specify it as the result ?

Thanks

Re: [struts] struts result going to a current page

Posted by Dale Newfield <Da...@Newfield.org>.
Dale Newfield wrote:
> The http return code 204 (or "no content") will leave the browser where 
> it was.

http://struts.apache.org/2.x/struts2-core/apidocs/org/apache/struts2/dispatcher/HttpHeaderResult.html

-Dale

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


Re: [struts] struts result going to a current page

Posted by Dale Newfield <Da...@Newfield.org>.
Dave Newton wrote:
> --- Dale Newfield <Da...@Newfield.org> wrote:
> ${#context.get(@org.apache.struts2.StrutsStatics@HTTP_REQUEST).getHeader("Referer")}
> 
> Ew.

Yep.

> It's almost enough to make me want to put the request object in as a named
> thingie.

You won't get an argument from me.

> That and the current action (as #action, I would have sworn we all
> talked about that at one point? to avoid issues with multiple pages,
> iterators, etc. and property shadowing).

+1

-Dale

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


Re: [struts] struts result going to a current page

Posted by Dave Newton <ne...@yahoo.com>.
--- Dale Newfield <Da...@Newfield.org> wrote:
>
${#context.get(@org.apache.struts2.StrutsStatics@HTTP_REQUEST).getHeader("Referer")}

Ew.

It's almost enough to make me want to put the request object in as a named
thingie. That and the current action (as #action, I would have sworn we all
talked about that at one point? to avoid issues with multiple pages,
iterators, etc. and property shadowing).

Dave



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


Re: [struts] struts result going to a current page

Posted by Dale Newfield <Da...@Newfield.org>.
Dave Newton wrote:
> --- Dale Newfield <Da...@Newfield.org> wrote:
>> P.S.:  If that request.getHeader bit doesn't work, it's because I think 
>> the OGNL #request object might be the request namespace rather than the 
>> actual HttpServletRequest object.
> 
> That's correct; #request is the request context, not the request itself.
> 
> I posted the OGNL for getting the actual request a few days ago; it's a
> little twisted. From that post (which was asking how to get the current
> request URL):
> 
> <s:property
> value="#context.get(@org.apache.struts2.StrutsStatics@HTTP_REQUEST).getRequestURL()"/>

Thanks.  Since this poster isn't asking for the request URL, but the 
page from which that request was submitted, which is the Referrer, I 
think that means they want:

<result name="redirectToReferrer" type="redirect">
   <param 
name="location">${#context.get(@org.apache.struts2.StrutsStatics@HTTP_REQUEST).getHeader("Referer")}</param>
</result>

-Dale

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


Re: [struts] struts result going to a current page

Posted by Dave Newton <ne...@yahoo.com>.
--- Dale Newfield <Da...@Newfield.org> wrote:
> P.S.:  If that request.getHeader bit doesn't work, it's because I think 
> the OGNL #request object might be the request namespace rather than the 
> actual HttpServletRequest object.

That's correct; #request is the request context, not the request itself.

I posted the OGNL for getting the actual request a few days ago; it's a
little twisted. From that post (which was asking how to get the current
request URL):

<s:property
value="#context.get(@org.apache.struts2.StrutsStatics@HTTP_REQUEST).getRequestURL()"/>

Dave


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


Re: [struts] struts result going to a current page

Posted by Dale Newfield <Da...@Newfield.org>.
Srinivas Surapaneni wrote:
> To be more specific, Here is we can do in Beehive Pageflow which is based on
> struts 1.x

Since I've never used Beehive, and I don't feel like digging through 
it's internals to figure out how it determines what the "previousPage" 
was, or how it forwards there, I can't tell you exactly what this does.

In general, though, what I'm telling you is that you have two choices. 
You can either have your global result of type httpheader and simply 
return 204 so the request completes but the person is left on whatever 
page they were previously viewing, or you can look in the request to see 
what the "referer" page is, and if set, you can send a redirect to it.

<global-results>
   <result name="noAnswer" type="httpheader">
     <param name="status">204</param>
   </result>
   <result name="redirectToReferrer" type="redirect">
     <param name="location">${#request.getHeader("Referer")}</param>
   </result>
</global-results>


<global-exception-mappings>
   <exception-mapping exception="recoverableExceptionBaseClass" 
result="one-of-the-two-above"/>
</global-exception-mappings>

-Dale

P.S.:  If that request.getHeader bit doesn't work, it's because I think 
the OGNL #request object might be the request namespace rather than the 
actual HttpServletRequest object.  I think that's a standard stumbling 
block, but it's late and I don't recall the standard solution -- can 
someone else please chime in?

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


Re: [struts] struts result going to a current page

Posted by Srinivas Surapaneni <sr...@gmail.com>.
To be more specific, Here is we can do in Beehive Pageflow which is based on
struts 1.x

I am trying to do a similar thing in Struts 2

@Jpf.ExceptionHandler(forwards = { @Jpf.Forward(name = "recoverableError",
navigateTo = Jpf.NavigateTo.page) })
 protected Forward handleRecoverableException(
   RecoverbaleException ex, String actionName,
   String message, Object form) throws Exception{
     // code
      this.addActionError(Globals.ERROR_KEY, key, null);
        return new Forward( "recoverbleError" );
 }
The above is the global exception handler. If any RecoverbaleException
happens anywhere in the application the request is send back to the current
page by means of Jpf.NavigareTo.Page

Thanks
On Feb 16, 2008 6:41 PM, Srinivas Surapaneni <sr...@gmail.com>
wrote:

> Yes,
>
> I want to return to whatever page referred the current request. Whenever a
> recoverable exception happens, I want to return to the current page so that
> user can take some action
>
> I am trying to avoid defining exception handling at each action level and
> do globally  and want to access the current page
>
> Thanks
>
>   On Feb 16, 2008 3:02 PM, Dale Newfield <Da...@newfield.org> wrote:
>
> > Srinivas Surapaneni wrote:
> > > I want the current page in the global exception handler. Instead of
> > giving a
> > > specific jsp page, I want to return to what ever the current page is
> >
> > That desire is not well specified.  Do you mean you want to return to
> > whatever page referred the current request?  Do you really want to
> > re-load that page (which may or may not be from within your webapp), or
> > is simply not changing the content currently being displayed sufficient?
> >
> > The http return code 204 (or "no content") will leave the browser where
> > it was.
> >
> > Otherwise it sounds like you want to redirect to the "referer" (yes,
> > it's misspelled in the specification).  Note if that page was the result
> > of a POST you pretty much can't redirect to it.
> >
> > -Dale
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>

Re: [struts] struts result going to a current page

Posted by Srinivas Surapaneni <sr...@gmail.com>.
Yes,

I want to return to whatever page referred the current request. Whenever a
recoverable exception happens, I want to return to the current page so that
user can take some action

I am trying to avoid defining exception handling at each action level and
do globally  and want to access the current page

Thanks

On Feb 16, 2008 3:02 PM, Dale Newfield <Da...@newfield.org> wrote:

> Srinivas Surapaneni wrote:
> > I want the current page in the global exception handler. Instead of
> giving a
> > specific jsp page, I want to return to what ever the current page is
>
> That desire is not well specified.  Do you mean you want to return to
> whatever page referred the current request?  Do you really want to
> re-load that page (which may or may not be from within your webapp), or
> is simply not changing the content currently being displayed sufficient?
>
> The http return code 204 (or "no content") will leave the browser where
> it was.
>
> Otherwise it sounds like you want to redirect to the "referer" (yes,
> it's misspelled in the specification).  Note if that page was the result
> of a POST you pretty much can't redirect to it.
>
> -Dale
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [struts] struts result going to a current page

Posted by Dale Newfield <Da...@Newfield.org>.
Srinivas Surapaneni wrote:
> I want the current page in the global exception handler. Instead of giving a
> specific jsp page, I want to return to what ever the current page is

That desire is not well specified.  Do you mean you want to return to 
whatever page referred the current request?  Do you really want to 
re-load that page (which may or may not be from within your webapp), or 
is simply not changing the content currently being displayed sufficient?

The http return code 204 (or "no content") will leave the browser where 
it was.

Otherwise it sounds like you want to redirect to the "referer" (yes, 
it's misspelled in the specification).  Note if that page was the result 
of a POST you pretty much can't redirect to it.

-Dale

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


Re: struts result going to a current page

Posted by Srinivas Surapaneni <sr...@gmail.com>.
I am working on struts2.

I cannot return null from the action.

I want the current page in the global exception handler. Instead of giving a
specific jsp page, I want to return to what ever the current page is

On Feb 16, 2008 1:55 PM, auz <f....@gmail.com> wrote:

>
> try returning null as an actionForward
> this works for ajax. its for struts 1.x
>
>
> Srinivas Surapaneni wrote:
> >
> > I want to define a global exception handler where if this exception
> > happens,
> > it goes to the current page
> >
> > Is there any way to get the current page and specify it as the result ?
> >
> > Thanks
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/struts-result-going-to-a-current-page-tp15509367p15518636.html
> Sent from the Struts - User mailing list archive at Nabble.com<http://nabble.com/>
> .
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: struts result going to a current page

Posted by auz <f....@gmail.com>.
try returning null as an actionForward
this works for ajax. its for struts 1.x


Srinivas Surapaneni wrote:
> 
> I want to define a global exception handler where if this exception
> happens,
> it goes to the current page
> 
> Is there any way to get the current page and specify it as the result ?
> 
> Thanks
> 
> 

-- 
View this message in context: http://www.nabble.com/struts-result-going-to-a-current-page-tp15509367p15518636.html
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