I see where the problem lies. Try to do the following:

private final class LocaleSwitchLink extends Link {

        private Locale toSwitch;

        @Override
        protected void onBeforeRender() {
                if (Session.get().getLocale().equals(toSwitch)) {
                        add(new AttributeModifier("class", true, new 
Model("yourActiveClass")));
                } else {
                        add(new AttributeModifier("class", true, new
Model("yourInactiveClass")));
                }
                super.onBeforeRender();
        }

        public LocaleSwitchLink (String s, Locale toSwitch) {
            super (s);
            this.toSwitch = toSwitch;
        }

        @Override
        public void onClick() {
            getSession().setLocale (toSwitch);
        }
}

that should work - i just tested it ... well similar code, not the exact
one. I did it with an ajaxlink :-)


Milan Křápek wrote:
> 
> well here are some code snippets:
> 
> Links without classes - everything is OK
> 
> private void addLocaleSwitchers() {
>         // add english link
>         enLink = new LocaleSwitchLink ("english", Locale.ENGLISH);
>         add (enLink);
>         // add czech link
>         czLink = new LocaleSwitchLink ("czech", new Locale ("cs"));
>         add (czLink);
> }
> 
> private final class LocaleSwitchLink extends Link {
> 
>         private Locale toSwitch;
> 
>         public LocaleSwitchLink (String s, Locale toSwitch) {
>             super (s);
>             this.toSwitch = toSwitch;
>         }
> 
>         @Override
>         public void onClick() {
>             getSession().setLocale (toSwitch);
>         }
> }
> 
> ------------------------------------------------------------------------------------------------------------------
> Links with classes - I do not know how to refresh locales in AjaxLink
> 
> private void addLocaleSwitchers() {
>         Locale currentLocale = this.getSession().getLocale();
>         // add english link
>         enLink = new LocaleSwitchLink ("english", Locale.ENGLISH);
>         if (currentLocale.equals(Locale.ENGLISH)) {
>             enLink.add (new AttributeModifier ("class", true, new Model
> ("activeLanguage")));
>         }
>         //enLink.setOutputMarkupId(true);
>         add (enLink);
>         // add czech link
>         czLink = new LocaleSwitchLink ("czech", new Locale ("cs"));
>         if (currentLocale.equals(new Locale("cs"))) {
>             czLink.add (new AttributeModifier ("class", true, new Model
> ("activeLanguage")));
>         }
>         //czLink.setOutputMarkupId(true);
>         add (czLink);
> }
> 
> private final class LocaleSwitchLink extends AjaxLink {
> 
>         private Locale toSwitch;
> 
>         public LocaleSwitchLink (String s, Locale toSwitch) {
>             super (s);
>             this.toSwitch = toSwitch;
>         }
> 
>         @Override
>         public void onClick (AjaxRequestTarget target) {
>             target.addComponent (enLink);
>             target.addComponent (czLink);
>             getSession().setLocale (toSwitch);
>         }
> }
> 
> I think that the problem is that I do not know how to set locale via
> ajaxRequestTarget.
> 
> Again thanks for any advices
> 
> Milan
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
> 
> 
> 


-----
Michael Sparer
http://talk-on-tech.blogspot.com
-- 
View this message in context: 
http://www.nabble.com/Localization---problem-with-refreshing-page-tp21085928p21089579.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to