我非常关注工作,但最后的障碍让我感到困惑。 我的用例:对于讨论小组,我必须根据讨论中的参与者数量显示i18n消息。所以,我有以下消息:
我选择使用片段,因为这似乎是最干净的方法,因此对于上述每个消息,我都有一个片段。对于第二个,这是:
<wicket:fragment wicket:id="recipients_1toMany">
<wicket:message key="heartbeat.wall.discussion.recipients.1toMany">
<span wicket:id="startedBy.displayName"></span>
<span wicket:id="firstRecipients"></span>
<span wicket:id="otherRecipientsCount"></span>
</wicket:message>
</wicket:fragment>
因此,wicket消息将编译文本+嵌入组件的变量(startedBy.displayName,...)。 此片段将添加到以下范围:
<span wicket:id="recipientsPlaceHolder"></span>
相关的java代码:
public class DiscussionPanel extends Panel {
public DiscussionPanel(final String id, final DiscussionTO discussion) {
super(id, new CompoundPropertyModel<DiscussionTO>(discussion));
...
final List<DiscussionParticipantTO> list = discussion.getParticipants();
String fragmentId = "recipients_1toMany"; //actually depends on list.size()
Fragment fragment = new Fragment("recipientsPlaceHolder", fragmentId, this);
Label startedByLabel = new Label("startedBy.displayName");
fragment.add(startedByLabel);
this.add(fragment);
}
}
这就像一个魅力。现在,最后一个障碍,我需要将 startedBy.displayName 作为链接呈现。
html更改:
<a href="#" wicket:id="showUser">
<span wicket:id="startedBy.displayName"></span>
</a>
代码更改:
ExternalLink showUserLink = new ExternalLink("showUser", "someurl");
showUserLink.add(startedByLabel);
fragment.add(showUserLink);
因此,不是将标签(startedByLabel)添加到片段中,而是将标签添加到链接并添加链接到片段。
现在,当面板渲染时,我得到以下异常:
Root cause:
org.apache.wicket.WicketRuntimeException: No get method defined for class: class com....DiscussionTO expression: recipientsPlaceHolder
at org.apache.wicket.util.lang.PropertyResolver.getGetAndSetter(PropertyResolver.java:499)
at org.apache.wicket.util.lang.PropertyResolver.getObjectAndGetSetter(PropertyResolver.java:341)
at org.apache.wicket.util.lang.PropertyResolver.getObjectAndGetSetter(PropertyResolver.java:244)
at org.apache.wicket.util.lang.PropertyResolver.getValue(PropertyResolver.java:97)
at org.apache.wicket.model.AbstractPropertyModel.getObject(AbstractPropertyModel.java:134)
at org.apache.wicket.Component.getDefaultModelObject(Component.java:1639)
at org.apache.wicket.markup.resolver.WicketMessageResolver$MessageContainer$1.getValue(WicketMessageResolver.java:266)
at org.apache.wicket.util.string.interpolator.VariableInterpolator.toString(VariableInterpolator.java:140)
at org.apache.wicket.markup.resolver.WicketMessageResolver$MessageContainer.renderMessage(WicketMessageResolver.java:249)
at org.apache.wicket.markup.resolver.WicketMessageResolver$MessageContainer.onComponentTagBody(WicketMessageResolver.java:208)
at org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onComponentTagBody(DefaultMarkupSourcingStrategy.java:72)
因此,出于某种原因,在链的某个地方解析消息,它试图在(模型对象)DiscussionTO上找到getRecipientsPlaceHolder(参见stacktrace中的WicketMessageResolver)。
似乎如果消息的变量(startedBy.displayName)与wicket:wicket无法找到它的wicket:message标签下的子节点的id不对应?
答案 0 :(得分:1)
<强>分辨强>
由于怀疑wicket消息解析器正在recipientsPlaceHolder中直接寻找名为'startedBy.displayName'的孩子。它不会比这更深入。 将链接的id更改为“startedBy.displayName”,或者像我一样,将文本资源中的变量更改为“showUser”。