1
votes

I am building a multilingual application and I am storing the value of the latest language used in a cookie.

When the user opens up the application, the sessionScope variable is not set and the code will look for the cookie value and reload the page if not in the proper Locale.

I am getting the "com.ibm.xsp.acl.RedirectSignal" warning each time the page is reloaded in the proper locale, and I'd lilke to avoid it.

My code is located in the beforeRenderResponse event of the ApplicationLayout control I am using in the application, and looks like this:

if(!sessionScope.lang) {  //this only happens when the page is opened in browser for the first time
    var lang = context.getUrlParameter("lang").toLowerCase();
    if(!!lang) {
            sessionScope.lang = lang.toUpperCase();
            //set cookie for next time the site is opened by user
            setCookie("lang", lang.toUpperCase(), 30);
            context.setLocale(new Locale(lang.toLowerCase()));
    } else {
        //set language from cookie
        var lang = getLangFromCookie();
        if(!!lang) {
            sessionScope.lang = lang;
            context.setLocale(new Locale(lang.toLowerCase()));
        } else {
            sessionScope.lang = Appconfig.defaultLang;
            context.setLocale(new Locale(Appconfig.defaultLang.toLowerCase()));
        }
    }

    //need to trpa the redirect error thrown here, as it is just a warning - avoid filling log with this
    //importPackage(com.ibm.xsp.acl.RedirectSignal);
    importPackage(com.ibm.xsp.acl.RedirectSignal);

    try {
        //reload the page so Locale value kicks in
        context.reloadPage();
    } catch (RedirectSignal rs) { 
        //just ignore
    }
}

Even though I added the importPackage line, I am still getting an error when saving the code (it is in a script Library):

Encountered " "rs"" at line...

How can I make this work?

Thanks :D

2

2 Answers

2
votes

The catch is a Throwable, not a RedirectSignal. Here's the code I use in my handleException function

try {
    try {
        if (t instanceof RedirectSignal) {
            return;
        }
        if ("javax.faces.el.EvaluationException".equals(t.getClass().getName())) {
            if (t.getCause() instanceof RedirectSignal) {
                return;
            }
        }
    } catch (Throwable e) {
        // Error checking cause, skip
    }
    // Now log the error
} catch (Throwable e) {
    e.printStackTrace();
}
1
votes

In SSJS you don't define the type/class of the exception in the catch block. Since you're not doing anything with the "exception", there's also no need to import the RedirectSignal class.

try {      
    context.reloadPage();
} catch ( redirectSignal ) { 
    // Ignore redirect signal "exception"
}