You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Alexandros Karypidis <ka...@gmail.com> on 2011/08/23 14:09:41 UTC

Basic l10n / i18n question: must page be re-rendered?

Hello,

I have written a locale selector by extending DropDownChoice (you can 
see the essential stuff of the implementation below). The problem is 
that when the user changes the locale, the page needs to be re-rendered 
using the newly selected locale. This does NOT happen. Instead, only the 
"<select>" input box seems to be refreshed to use the new locale, 
whereas the rest of the page content is still rendered using the 
previously selected locale. However, the locale has been changed in the 
Session which can be seen when the user navigates to another page (e.g. 
by clicking on a link), as the new page is rendered using the 
newly-selected locale.

So, how can I force the current page to be re-rendered?

Implementation of my locale selector is as follows:

Markup: <select wicket:id="localeSelection"></select>
Component code:
public class LocaleDropDown extends DropDownChoice<Locale> {
//...
     public LocaleDropDown(final String id, final List<Locale> choices) {
     // ...
         setModel(new IModel<Locale>() {
             public Locale getObject() {
                 return getSession().getLocale();
             }
             @Override
             public void setObject(Locale locale) {
                 getSession().setLocale(locale);
                 // need something here to tell wicket to refresh the 
entire page?
             }
         });
     // ...
     }

     @Override
     protected boolean wantOnSelectionChangedNotifications() {
         // post an event when user changes the selected value in the 
drop-down box
         return true;
     }
}

-- Kind regards, Alex

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


Re: Basic l10n / i18n question: must page be re-rendered?

Posted by Alexandros Karypidis <ak...@yahoo.gr>.
Hi again,

Just to add to this that the following will work for pages with parameters:

     @Override
     protected void onSelectionChanged(Locale newSelection) {
         super.onSelectionChanged(newSelection);
         // the following tells wicket to instantiate a new page using 
the current page's class
         getRequestCycle().setResponsePage(getPage().getClass(), 
getPage.getParameters());
     }


On 23/8/2011 10:41 μμ, Alexandros Karypidis wrote:
> Hi Gregor,
>
> I've found a way to do this by manipulating the request cycle. 
> However, it will only work if you don't mind losing any page state, as 
> it generates a new page rendering. I do this by overriding 
> onSelectionChanged(...) of the DropDownChoice<Locale> as follows:
>
>     @Override
>     protected void onSelectionChanged(Locale newSelection) {
>         super.onSelectionChanged(newSelection);
>         // the following tells wicket to instantiate a new page using 
> the current page's class
>         getRequestCycle().setResponsePage(getPage().getClass());
>     }
>
> Maybe a more knowledgeable user could suggest a better alternative?
>
> On 23/8/2011 9:13 μμ, Gregor Kaczor wrote:
>> I have exactly the same problem, though i use an xml file for the 
>> translations. Any help out there?
>>
>> On 08/23/2011 02:09 PM, Alexandros Karypidis wrote:
>>> Hello,
>>>
>>> I have written a locale selector by extending DropDownChoice (you 
>>> can see the essential stuff of the implementation below). The 
>>> problem is that when the user changes the locale, the page needs to 
>>> be re-rendered using the newly selected locale. This does NOT 
>>> happen. Instead, only the "<select>" input box seems to be refreshed 
>>> to use the new locale, whereas the rest of the page content is still 
>>> rendered using the previously selected locale. However, the locale 
>>> has been changed in the Session which can be seen when the user 
>>> navigates to another page (e.g. by clicking on a link), as the new 
>>> page is rendered using the newly-selected locale.
>>>
>>> So, how can I force the current page to be re-rendered?
>>>
>>> Implementation of my locale selector is as follows:
>>>
>>> Markup: <select wicket:id="localeSelection"></select>
>>> Component code:
>>> public class LocaleDropDown extends DropDownChoice<Locale> {
>>> //...
>>>     public LocaleDropDown(final String id, final List<Locale> 
>>> choices) {
>>>     // ...
>>>         setModel(new IModel<Locale>() {
>>>             public Locale getObject() {
>>>                 return getSession().getLocale();
>>>             }
>>>             @Override
>>>             public void setObject(Locale locale) {
>>>                 getSession().setLocale(locale);
>>>                 // need something here to tell wicket to refresh the 
>>> entire page?
>>>             }
>>>         });
>>>     // ...
>>>     }
>>>
>>>     @Override
>>>     protected boolean wantOnSelectionChangedNotifications() {
>>>         // post an event when user changes the selected value in the 
>>> drop-down box
>>>         return true;
>>>     }
>>> }
>>>
>>> -- Kind regards, Alex
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org


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


Re: Basic l10n / i18n question: must page be re-rendered?

Posted by Alexandros Karypidis <ak...@yahoo.gr>.
Hi Gregor,

I've found a way to do this by manipulating the request cycle. However, 
it will only work if you don't mind losing any page state, as it 
generates a new page rendering. I do this by overriding 
onSelectionChanged(...) of the DropDownChoice<Locale> as follows:

     @Override
     protected void onSelectionChanged(Locale newSelection) {
         super.onSelectionChanged(newSelection);
         // the following tells wicket to instantiate a new page using 
the current page's class
         getRequestCycle().setResponsePage(getPage().getClass());
     }

Maybe a more knowledgeable user could suggest a better alternative?

On 23/8/2011 9:13 μμ, Gregor Kaczor wrote:
> I have exactly the same problem, though i use an xml file for the 
> translations. Any help out there?
>
> On 08/23/2011 02:09 PM, Alexandros Karypidis wrote:
>> Hello,
>>
>> I have written a locale selector by extending DropDownChoice (you can 
>> see the essential stuff of the implementation below). The problem is 
>> that when the user changes the locale, the page needs to be 
>> re-rendered using the newly selected locale. This does NOT happen. 
>> Instead, only the "<select>" input box seems to be refreshed to use 
>> the new locale, whereas the rest of the page content is still 
>> rendered using the previously selected locale. However, the locale 
>> has been changed in the Session which can be seen when the user 
>> navigates to another page (e.g. by clicking on a link), as the new 
>> page is rendered using the newly-selected locale.
>>
>> So, how can I force the current page to be re-rendered?
>>
>> Implementation of my locale selector is as follows:
>>
>> Markup: <select wicket:id="localeSelection"></select>
>> Component code:
>> public class LocaleDropDown extends DropDownChoice<Locale> {
>> //...
>>     public LocaleDropDown(final String id, final List<Locale> choices) {
>>     // ...
>>         setModel(new IModel<Locale>() {
>>             public Locale getObject() {
>>                 return getSession().getLocale();
>>             }
>>             @Override
>>             public void setObject(Locale locale) {
>>                 getSession().setLocale(locale);
>>                 // need something here to tell wicket to refresh the 
>> entire page?
>>             }
>>         });
>>     // ...
>>     }
>>
>>     @Override
>>     protected boolean wantOnSelectionChangedNotifications() {
>>         // post an event when user changes the selected value in the 
>> drop-down box
>>         return true;
>>     }
>> }
>>
>> -- Kind regards, Alex
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>
>


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


Re: Basic l10n / i18n question: must page be re-rendered?

Posted by Igor Vaynberg <ig...@gmail.com>.
the pub and form input examples works correctly, take a look at those.

-igor


On Tue, Aug 23, 2011 at 11:13 AM, Gregor Kaczor <gk...@gmx.de> wrote:
> I have exactly the same problem, though i use an xml file for the
> translations. Any help out there?
>
> On 08/23/2011 02:09 PM, Alexandros Karypidis wrote:
>>
>> Hello,
>>
>> I have written a locale selector by extending DropDownChoice (you can see
>> the essential stuff of the implementation below). The problem is that when
>> the user changes the locale, the page needs to be re-rendered using the
>> newly selected locale. This does NOT happen. Instead, only the "<select>"
>> input box seems to be refreshed to use the new locale, whereas the rest of
>> the page content is still rendered using the previously selected locale.
>> However, the locale has been changed in the Session which can be seen when
>> the user navigates to another page (e.g. by clicking on a link), as the new
>> page is rendered using the newly-selected locale.
>>
>> So, how can I force the current page to be re-rendered?
>>
>> Implementation of my locale selector is as follows:
>>
>> Markup: <select wicket:id="localeSelection"></select>
>> Component code:
>> public class LocaleDropDown extends DropDownChoice<Locale> {
>> //...
>>    public LocaleDropDown(final String id, final List<Locale> choices) {
>>    // ...
>>        setModel(new IModel<Locale>() {
>>            public Locale getObject() {
>>                return getSession().getLocale();
>>            }
>>            @Override
>>            public void setObject(Locale locale) {
>>                getSession().setLocale(locale);
>>                // need something here to tell wicket to refresh the entire
>> page?
>>            }
>>        });
>>    // ...
>>    }
>>
>>    @Override
>>    protected boolean wantOnSelectionChangedNotifications() {
>>        // post an event when user changes the selected value in the
>> drop-down box
>>        return true;
>>    }
>> }
>>
>> -- Kind regards, Alex
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>
>
> --
> How to find files on the Internet? FindFiles.net <http://findfiles.net>!
>

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


Re: Basic l10n / i18n question: must page be re-rendered?

Posted by Gregor Kaczor <gk...@gmx.de>.
I have exactly the same problem, though i use an xml file for the 
translations. Any help out there?

On 08/23/2011 02:09 PM, Alexandros Karypidis wrote:
> Hello,
>
> I have written a locale selector by extending DropDownChoice (you can 
> see the essential stuff of the implementation below). The problem is 
> that when the user changes the locale, the page needs to be 
> re-rendered using the newly selected locale. This does NOT happen. 
> Instead, only the "<select>" input box seems to be refreshed to use 
> the new locale, whereas the rest of the page content is still rendered 
> using the previously selected locale. However, the locale has been 
> changed in the Session which can be seen when the user navigates to 
> another page (e.g. by clicking on a link), as the new page is rendered 
> using the newly-selected locale.
>
> So, how can I force the current page to be re-rendered?
>
> Implementation of my locale selector is as follows:
>
> Markup: <select wicket:id="localeSelection"></select>
> Component code:
> public class LocaleDropDown extends DropDownChoice<Locale> {
> //...
>     public LocaleDropDown(final String id, final List<Locale> choices) {
>     // ...
>         setModel(new IModel<Locale>() {
>             public Locale getObject() {
>                 return getSession().getLocale();
>             }
>             @Override
>             public void setObject(Locale locale) {
>                 getSession().setLocale(locale);
>                 // need something here to tell wicket to refresh the 
> entire page?
>             }
>         });
>     // ...
>     }
>
>     @Override
>     protected boolean wantOnSelectionChangedNotifications() {
>         // post an event when user changes the selected value in the 
> drop-down box
>         return true;
>     }
> }
>
> -- Kind regards, Alex
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


-- 
How to find files on the Internet? FindFiles.net <http://findfiles.net>!