Reading localization properties from Page Subclass .properties file

View: New views
2 Messages — Rating Filter:   Alert me  

Reading localization properties from Page Subclass .properties file

by Leo Erlandsson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

We are in the process of moving our applications from JSP to Wicket.
Right now we're writing a framework with BasePages and base components to
build on and are
learning Wicket "on the fly".

The BasePage contains a HeaderPanel which renders the "Headline" of the
page:

<!-- BasePage.java -->
   public BasePage() {

        super();
        .
        .
        header = new HeaderPanel("header", getHeaderImagePath());
        add(header);

}


We then subclass BasePage and implement getHeaderImagePath() which is
abstract.
HeaderPanel reads the header from a .properties file and uses a different
resourceKey
depending on what "mode" the page is in. E.g. if the page is in "edit
mode", the HeaderPanel
tries to read editHeadline, and if the page is in "view mode" the
HeaderPanel tries to read
viewHeadline:

<!-- Extract from HeaderPanel.java constructor -->
add(new Label("viewHeadline",
                new StringResourceModel("viewHeadline",
                this, model)) {

            @Override
            public boolean isVisible() {
                return getMode() == Mode.VIEW;
            }
        }.setRenderBodyOnly(true));


<!-- SubclassPage.java -->
public class SubclassPage extends BasePage
        public  SubclassPage() {
 
                super();

        }
}


Now for the "problem":

We would like to be able to read the localization properties from the Page
_Subclass_ .properties file.
This apparently won't work because the HeaderPanel is added in BasePage
constructor, and uses
that as "parent component" to HeaderPanel in the StringResourceModel.

Of course we can create methods like getViewHeadline() and force the Page
subclass to
implement/override them, but is there a better way?

Is it possible to get the values from the Page Subclass .properties file?

Thanks!

Regards,
Leo
---
Leo Erlandsson, M. Sc.

Re: Reading localization properties from Page Subclass .properties file

by igor.vaynberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

create a model that always looks for the page and asks it for
properties, use existing resourcemodel as an example, but where
resource model does

return Application.get().getResourceSettings().getLocalizer().getString(resourceKey,
                                component, defaultValue);

you do

return Application.get().getResourceSettings().getLocalizer().getString(resourceKey,
                                component.getPage(), defaultValue);


alternatively just use a simple label

class pageresourcelabel extends label {
    public pageresourcelabel(stirng id, string resourcekey) {
        super(id, new abstractreadonlymodel() {
               getobject() { return getpage().getstring(resourcekey); }}}}

-igor


On Thu, Nov 5, 2009 at 11:41 PM,  <Leo.Erlandsson@...> wrote:

> Hi,
>
> We are in the process of moving our applications from JSP to Wicket.
> Right now we're writing a framework with BasePages and base components to
> build on and are
> learning Wicket "on the fly".
>
> The BasePage contains a HeaderPanel which renders the "Headline" of the
> page:
>
> <!-- BasePage.java -->
>   public BasePage() {
>
>        super();
>        .
>        .
>        header = new HeaderPanel("header", getHeaderImagePath());
>        add(header);
>
> }
>
>
> We then subclass BasePage and implement getHeaderImagePath() which is
> abstract.
> HeaderPanel reads the header from a .properties file and uses a different
> resourceKey
> depending on what "mode" the page is in. E.g. if the page is in "edit
> mode", the HeaderPanel
> tries to read editHeadline, and if the page is in "view mode" the
> HeaderPanel tries to read
> viewHeadline:
>
> <!-- Extract from HeaderPanel.java constructor -->
> add(new Label("viewHeadline",
>                new StringResourceModel("viewHeadline",
>                this, model)) {
>
>            @Override
>            public boolean isVisible() {
>                return getMode() == Mode.VIEW;
>            }
>        }.setRenderBodyOnly(true));
>
>
> <!-- SubclassPage.java -->
> public class SubclassPage extends BasePage
>        public  SubclassPage() {
>
>                super();
>
>        }
> }
>
>
> Now for the "problem":
>
> We would like to be able to read the localization properties from the Page
> _Subclass_ .properties file.
> This apparently won't work because the HeaderPanel is added in BasePage
> constructor, and uses
> that as "parent component" to HeaderPanel in the StringResourceModel.
>
> Of course we can create methods like getViewHeadline() and force the Page
> subclass to
> implement/override them, but is there a better way?
>
> Is it possible to get the values from the Page Subclass .properties file?
>
> Thanks!
>
> Regards,
> Leo
>

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