Click Framework  History | Log In     View a printable version of the current page. Get help!  
Issue Details (XML | Word)

Key: CLK-456
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Bob Schellink
Reporter: Ricardo R. Lecheta
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Click

Page.setRedirect problem?

Created: 09/Oct/08 04:47 AM   Updated: 17/Oct/08 03:56 PM
Component/s: None
Affects Version/s: 1.5 RC2
Fix Version/s: 1.5 RC3


 Description  « Hide
Hi, since the setRedirect logic was moved to the Page control...
we must validate to guarantee that the "contextPath" will not be appended to the url twice.

if you call setRedirect() two times (i know it´s strange but it´s possible), it will duplicate the contextPath...

This is how I fixed this for my app:

    /**
     * @see net.sf.click.Page#setRedirect(java.lang.String)
     */
    public void setRedirect(String location) {
        if (location != null) {
            if (location.charAt(0) == '/') {
                Context context = getContext();
                String contextPath = context.getRequest().getContextPath();
                if(!location.startsWith(contextPath)){
location = contextPath + location;
                }
            }
        }
        redirect = location;
    }

 All   Comments   Change History      Sort Order:
Bob Schellink [09/Oct/08 06:03 AM]
Do you mean setRedirect(getRedirect()) will append the context multiple times?

Because invoking setRedirect multiple times with a location seems to work:

public void onInit() {
    setRedirect("/test.htm");
    setRedirect("/test.htm");
}

This produced '/mycontext/test.htm'

Ricardo R. Lecheta [10/Oct/08 08:45 AM]
Hi Bob,

yes you are right.

but if the redirect already have the context ?

public void onInit() {
    setRedirect("/myContext/test.htm");
    setRedirect("/myContext/test.htm");
}

this happened to me, because I wrote some crazy logic to create some redirect String :-)

i know it looks strange, but it´s possible. I just think we should handle it...

Bob Schellink [12/Oct/08 02:35 AM]
Thanks for the pickup Ricardo. Fixed in trunk