Let me be the first to say: Happy new year!!!
I'll try the auto-pickup of the labels when I get back in to the office
on Monday. I haven't used stateful pages before, so I'll check that out
as well.
Cheers!
WarnerJan
On 01-Jan-10 04:08, Bob Schellink wrote:
Hi WarnerJan,
I agree, creating a composite control and "pushing" the localized
messages to child controls, its best to move the getMessage method
outside the constructor to one of the event handlers (onInit,
onRender) or even the #render method.
Also note that fields have the convention where it automatically picks
up a localized message based on its name and '.label' postfix so it
might not be necessary to push the messages:
username.label=First Name
Keep in mind that stateful pages could create problems with adding
controls in the onInit event because onInit is invoked each request.
So either create the controls in the constructor and set the label
during onInit, or do a check in onInit if the control is already present:
public class LoginForm extends Form {
private TextField username;
public LoginForm() {
add(username = new TextField("username", true));
}
public onInit() {
username.setLabel(getMessage("label_username"));
}
}
kind regards
bob
PS: At some stage we need to add a "How to write controls" section to
the docs to address these ins and outs.
WarnerJan Veldhuis wrote:
It might be worth mentioning in the docs that when subclassing forms
and using i18n, you should place control creation in onInit(),
instead of the constructor.
This example will not use i18n, since getMessage() does not have a
parent context:
public class LoginForm extends Form {
public *LoginForm()* {
TextField username = new TextField("username",
getMessage("label_username"), true);
add(username);
}
}
This example works with i18n, at least, using onInit() is how I
solved this issue:
public class LoginForm extends Form {
public LoginForm() {
}
public *onInit()* {
TextField username = new TextField("username",
getMessage("label_username"), true);
add(username);
}
}
Is this assumption correct?
Cheers,
WarnerJan