Hi,

You should also override #mapHandler() method to produce Urls
depending on the current locale.

On Mon, Apr 23, 2012 at 6:12 PM, sb <[email protected]> wrote:
> Hi,
>
> I'm new to wicket I'm trying to map two different paths like
>
> /first.html
>
> /primero.html
>
> to the same page and depending on the mount used the Locale should be set so
> that the site is internationalized.
>
> I've overriden MountedMapper with the following:
> ---- CODE START ----
> import org.apache.wicket.Session;
> import org.apache.wicket.markup.html.WebPage;
> import org.apache.wicket.request.IRequestHandler;
> import org.apache.wicket.request.Request;
> import org.apache.wicket.request.mapper.MountedMapper;
>
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> import java.util.Locale;
>
> public class LocalizedMountedMapper extends MountedMapper {
>   private static final Logger log =
> LoggerFactory.getLogger(LocalizedMountedMapper.class);
>   private final Locale locale;
>
>   public LocalizedMountedMapper(String _path, Class<? extends WebPage>
> _page, Locale _locale) {
>      super(_path, _page);
>      this.locale = _locale;
>   }
>
>   public IRequestHandler mapRequest(Request _request) {
>      // RequestCycle#getSession no longer seems to work or even be there.
>      Session session = Session.get();
>      session.setLocale(locale);
>      log.debug("setting locale: " + locale + " / " +
> _request.getContextPath());
>      return super.mapRequest(_request);
>   }
> }
> ---- CODE END ----
>
> Then in the application class I add the following to the init method
>
> ---- CODE START ----
> mount(new LocalizedMountedMapper("/first.html", HomePage.class,
> Constants.LOCALE_en));
>
> mount(new LocalizedMountedMapper("/primero.html", HomePage.class,
> Constants.LOCALE_es_AR));
> ---- CODE END ----
>
> But this does not seem to work.  When I point my browser at
> http://localhost:8080/first.html the browser redirects to
> http://localhost:8080/primero.html
>
> and the output of the logging is the following:
>
> DEBUG - LocalizedMountedMapper     - setting locale: en / en_US /  /
> DEBUG - LocalizedMountedMapper     - setting locale: es_AR / en_US /  /
>
> Does anyone have suggestions about why it doesn't work as I expect it to and
> how to correct it.  Or any suggestions about a better way to achieve this
> functionality.
>
> Cheers
> Simon
>
> --
> View this message in context: 
> http://apache-wicket.1842946.n4.nabble.com/Mapping-different-paths-to-the-same-page-and-updating-session-Locale-tp4580714p4580714.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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

Reply via email to