我什么时候可以在 Wicket Ajax TabbedPanel 中使用 getString()?
When can I use getString() in a Wicket Ajax TabbedPanel?
我在使用 Wicket 7.3 和 JQuery 2.1.4 时遇到以下问题:
在动态选项卡式面板(添加和删除选项卡)中,我想本地化选项卡标题并添加工具提示。我的代码
JQueryGenericPanel() {
....
populateItem( ListItem<ITab> item) {
getString();
导致日志文件中出现警告:
Tried to retrieve a localized string for a component that has not yet been added to the page. This can sometimes lead to an invalid or no localized resource returned. Make sure you are not calling Component#getString() inside your Component's constructor
在其方法中的面板(位于选项卡上)中使用 getString()
onInitialize()
不行,因为太晚了。标签已设置为 "lazy".
有没有其他类似于"populateItem()"的方法可以使用?
** 附录 **
标签面板的代码是:
public class MyTabbedPanel extends JQueryGenericPanel<List<ITab>> implements ITabsListener {
...
@Override
protected void onInitialize() {
super.onInitialize();
this.add( new ListView<ITab>( "tabs", this.getModel() ) {
...
@Override
protected void populateItem( ListItem<ITab> item ) {
Label link = new Label( "widgetId", new PropertyModel<String>( somePanel, "getTitle()" ) );
面板中的代码是:
private String title = "default";
public String getTitle() { return title; }
@Override
public void onInitialize() {
title = getString( "someKey" );
}
因此 PropertyModel 使用 'getTitle()' 获取标题。不幸的是,这发生在 'onInitialize()' 被调用之前。因此选项卡标题显示 "default" 而不是 "someKey".
的本地化文本
而不是
new Label(itemId, getString("key"))
... 使用:
new Label(itemId, new ResourceModel("key"));
... 或者如果您对字符串做了一些花哨的事情:
new Label(itemId, new AbstractReadOnlyModel<String>() {
public String getObject() {
return ... + getString("key") + ...;
}
});
我在使用 Wicket 7.3 和 JQuery 2.1.4 时遇到以下问题:
在动态选项卡式面板(添加和删除选项卡)中,我想本地化选项卡标题并添加工具提示。我的代码
JQueryGenericPanel() {
....
populateItem( ListItem<ITab> item) {
getString();
导致日志文件中出现警告:
Tried to retrieve a localized string for a component that has not yet been added to the page. This can sometimes lead to an invalid or no localized resource returned. Make sure you are not calling Component#getString() inside your Component's constructor
在其方法中的面板(位于选项卡上)中使用 getString()
onInitialize()
不行,因为太晚了。标签已设置为 "lazy".
有没有其他类似于"populateItem()"的方法可以使用?
** 附录 ** 标签面板的代码是:
public class MyTabbedPanel extends JQueryGenericPanel<List<ITab>> implements ITabsListener {
...
@Override
protected void onInitialize() {
super.onInitialize();
this.add( new ListView<ITab>( "tabs", this.getModel() ) {
...
@Override
protected void populateItem( ListItem<ITab> item ) {
Label link = new Label( "widgetId", new PropertyModel<String>( somePanel, "getTitle()" ) );
面板中的代码是:
private String title = "default";
public String getTitle() { return title; }
@Override
public void onInitialize() {
title = getString( "someKey" );
}
因此 PropertyModel 使用 'getTitle()' 获取标题。不幸的是,这发生在 'onInitialize()' 被调用之前。因此选项卡标题显示 "default" 而不是 "someKey".
的本地化文本而不是
new Label(itemId, getString("key"))
... 使用:
new Label(itemId, new ResourceModel("key"));
... 或者如果您对字符串做了一些花哨的事情:
new Label(itemId, new AbstractReadOnlyModel<String>() {
public String getObject() {
return ... + getString("key") + ...;
}
});