使用 <wicket:message>生成部分格式化文本的标签

编程入门 行业动态 更新时间:2024-10-19 15:41:29
本文介绍了使用 <wicket:message>生成部分格式化文本的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我读过 wicket:message 这里,但似乎无法让它做我想做的一切.

I've read about wicket:message here, but can't seem to make it do everything I'd like.

假设我有一个带有 <wicket:message key="text"/> 的 HTML 页面和一个包含 text=Blah blah: important point, foo bar 的属性文件代码>.我想知道如何将文本的 part 设为粗体(或对其应用任意 CSS),以实现如下输出:

Say I have a HTML page with <wicket:message key="text"/> and a properties file containing text=Blah blah: important point, foo bar. I'm wondering how to make part of the text bold (or apply arbitrary CSS to it), to achieve output like:

废话废话:重点,foo bar

Blah blah: important point, foo bar

请注意,这些实际上都不是动态,所以如果可以避免的话,我不想用 Java 做任何事情.

Note that none of this is actually dynamic, so I wouldn't want to do anything in Java, if that can be avoided.

我尝试过使用类似以下内容的嵌套标签,但没有成功.

I've tried nesting tags with something like the following, but no luck.

<wicket:message key="text">
    <span class="bold"><wicket:message key="text2"/></span>
</wicket:message>

text=Blah blah: ${text2}, foo bar
text2=important point

这在 Wicket 中是否可行,而无需 1) 从 Java 端注入格式化部分或 2) 仅将文本拆分为(在本例中)三个不同的属性?

Is this even possible in Wicket without 1) injecting the formatted part from Java side or 2) just splitting the text into (in this case) three different properties?

推荐答案

最简单的方法是将标签放在本地化文件中:

The easiest way is to put the tags inside your localization file:

text=废话:<strong>text2</strong>, foo bar

text=Blah blah: <strong>text2</strong>, foo bar

您也可以稍后使用标签和资源模型来替换它:

You could also use a Label and a ResourceModel to replace it later:

text=废话:[b]text2[/b], foo bar

text=Blah blah: [b]text2[/b], foo bar

在你的模型中 getObject() 或在你的标签中:

And in your model getObject(), or in your Label:

string.replace("[b]", "");
string.replace("[/b]", "</strong>");

string.replace("[b]", "<strong>");
string.replace("[/b]", "</strong>");

或者,更好的是,尝试在您的标签中重用 Markdown 实现.

Or, even better, try to reuse a Markdown implementation in your Label.

这篇关于使用 &lt;wicket:message&gt;生成部分格式化文本的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 03:10:56,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本   标签   lt   amp   wicket

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!