Re: Localization - problem with refreshing page

2008-12-19 Thread Michael Sparer

Please show us some code. ... sounds like a improper use of models 

regards,
Michael

Milan Křápek wrote:
 
 Hi,
   I found this problem and I cannot find any sollution by myself. So I ask
 you for a help.
 
 I localized my application to two languages. To all pages I added links
 for changing localization. The onClick() methods of those links contain
 just getSession.setLocale(requestedLocalization). That works great after
 click on the links all texts in my page are localized to the right
 language.
 The problem occurs when I need to style my page by CSS. I need to add
 class to the generated links for localization to know which language is
 active. So I added new AttributeModifier to those links. But when
 setLocale() is called, the page refreshs only text and I need to reload
 the localization links component too.
 I tried to change my localization links to AjaxLinks and in onClick()
 methos add the component to AjaxRequestTarget and then call setLocale().
 But when I do this the localization links are rerendered as I expected and
 CSS classes are set correctly but the texts are not localized. Please
 help, how can I do these two things together?
 
 thanks for any advice
 
 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-tp21085928p21088004.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



Re: Localization - problem with refreshing page

2008-12-19 Thread Michael Sparer

Yep, right. Better. 


James Carman-3 wrote:
 
 You don't have to use onBeforeRender() here.  You can have your model
 calculate what class to use based on the currently selected locale:
 
 new ModelString()
 {
   public String getObject()
   {
 if(toSwitch.equals(Session.get().getLocale()))
 {
   return active;
 }
 else
 {
   return inactive;
 }
   }
 }
 
 On Fri, Dec 19, 2008 at 6:10 AM, Michael Sparer michael.spa...@gmx.at
 wrote:

 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


 
 


-
Michael Sparer
http://talk-on-tech.blogspot.com
-- 
View this message in context: 
http://www.nabble.com/Localization---problem-with-refreshing-page-tp21085928p21090097.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



Localization - problem with refreshing page

2008-12-18 Thread Milan Křápek
Hi,
  I found this problem and I cannot find any sollution by myself. So I ask you 
for a help.

I localized my application to two languages. To all pages I added links for 
changing localization. The onClick() methods of those links contain just 
getSession.setLocale(requestedLocalization). That works great after click on 
the links all texts in my page are localized to the right language.
The problem occurs when I need to style my page by CSS. I need to add class to 
the generated links for localization to know which language is active. So I 
added new AttributeModifier to those links. But when setLocale() is called, the 
page refreshs only text and I need to reload the localization links component 
too.
I tried to change my localization links to AjaxLinks and in onClick() methos 
add the component to AjaxRequestTarget and then call setLocale(). But when I do 
this the localization links are rerendered as I expected and CSS classes are 
set correctly but the texts are not localized. Please help, how can I do these 
two things together?

thanks for any advice

Milan

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