appendToResponse and redirecting a user

Piers Uso Walter piers at mail.rol-berlin.de
Wed Apr 7 11:33:04 PDT 1999


You wrote:
> What would the proper way be of redirecting a user to a different page
> from within the appendToResponse:inContext: method?
>
> This is in an app made completely of direct actions, so I can redirect
> directly to the page. However, I tried setting the location header value
> to the page url, but that doesn't seem to be doing it.
>
> (doing everything with direct actions really requires you to think quite
> differently. I'm doing this app as a sort-of experiment, just to get
> used to direct actions. However, I'll probably continue and even deploy if
> everything works out.
>
> One thing that is immediately different is that you'll probably include
> key values in many more of your eo's. Plus, you're just thinking a lot
> more in the manner as if you were creating an asp application. )

I'm still running WO 3.5.1, so no direct actions here. But nonetheless I can  
provide you with a tried (but somewhat awkward) solution to redirection from  
within the appendToResponse:inContext: method.

Note: I've just typed this into the mail without testing it, so there are  
going to be some typos that'll have to be eliminated before this'll work.

If WO URL syntax has changed from 3.5 to 4.0, you would have to modify the  
method setElementIdOf:to: accordingly, but I'm sure you get the basic idea of  
what I'm doing.


------------------------------------------------------------------
Test.wo/Test.html:

<HTML>
<HEAD></HEAD>
<BODY>

<WEBOBJECT name=INVISIBLE_LINK></WEBOBJECT>

</BODY>
</HTML>

------------------------------------------------------------------
Test.wo/Test.wod:

INVISIBLE_LINK: WOHyperlink {
//	action = whateverYouNeedToAccessTheFollowupPage;
	pageName = nameOfFollowupPage;
};

------------------------------------------------------------------
Test.wo/Test.wos:

- whateverYouNeedToAccessTheFollowupPage
   // NOTE: Use only if you can't do your stuff with WOHyperlink's pageName
{
	id	followupPage;

	followupPage = ... (some magic);

	return followupPage
}


- (NSString *)setElementIdOf:(NSString *)anUrl to:(NSString *)anIdString
    // Sets anUrl's element Id to anIdString.
    // Returns the modified URL.
    // Used for dynamic creation of WO URLs
{
    NSMutableArray	*urlElements;
    unsigned int	indexOfElementId;

    // Retrieve element Id and split into components:
    urlElements = [NSMutableArray arrayWithArray:
        [anUrl componentsSeparatedByString:@"/"]];
    indexOfElementId = [urlElements count] - 3;

    // Replace element Id:
    [urlElements replaceObjectAtIndex:indexOfElementId
                           withObject:anIdString];

    // Return modified URL:
    return [urlElements componentsJoinedByString:@"/"];
} // setElementIdOf:to:


- appendToResponse:(WOResponse *)aResponse
         inContext:(WOContext *)aContext
{
    // Create followupURL pointing to this page again:
    followupURL = [[[self session] context] url];

    // Insert element Id of the "invisible" link at the top of the page:
    followupURL = [self setElementIdOf:followupURL to:@"0"];

    // Set redirect header to modified URL of this page so that it
    // 'triggers' the "invisible" link at the top of the page:
    [aResponse setStatus:302];
    [aResponse setHeader:followupURL forKey:@"location"];
    [aResponse setHeader:@"text/html" forKey:@"content-type"];
}

------------------------------------------------------------------

Regards

Piers Uso Walter <piers at ilink.de>



More information about the OmniWeb-l mailing list