Wicket:如何以编程方式呈现页面并将结果作为字符串? [英] Wicket: how to render page programmatically and get result as string?

查看:127
本文介绍了Wicket:如何以编程方式呈现页面并将结果作为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将应用转换为在其所有页面上使用i18n / l10n。我对Wicket对此的支持感到非常满意,到目前为止一切顺利。我遇到的一个棘手的部分如下:

I'm in the process of converting an app to use i18n/l10n on all its pages. I'm very happy with Wicket's support for this, and it's going well so far. The one tricky part I've run into is the following:

我们有一个文本文件,用作HTML模板,用于在用户执行特定操作时发送电子邮件网站。当用户点击特定链接时,我手动读取此模板,执行一些文本替换,如亲爱的$ USERNAME,并将结果作为HTML电子邮件发送给用户。

We have a text file that is used as an HTML template to send email when users perform a certain operation on the site. When the user clicks a particular link, I read in this template manually, do some text substitutions like "Dear $USERNAME", and send the result as an HTML email to the user.

为了支持我们定位的10种左右的语言,我要么必须维护此模板文件的10个副本,要么找到一种方法使用Wicket的内置i18n支持渲染此页面,将结果作为字符串抓取,然后发送。

In order to support the 10 or so languages we're targeting, I'll either have to maintain 10 copies of this template file, or figure out a way to render this "page" using Wicket's built-in i18n support, grab the result as a string, and then send it.

因此我的问题 :我如何以编程方式呈现Wicket页面并将结果作为字符串获取?

Hence my question: how can I "render" a Wicket page programmatically and get the result as a string?

我宁愿避免使用像HttpClient这样的黑客攻击,如果可能的话; HttpClient不会有用户的Locale,也不会以用户等身份自动登录,所以这对我来说似乎不是一个好的解决方案。

I'd prefer to avoid hacks like using HttpClient if at all possible; HttpClient won't have the user's Locale, won't be automatically logged in as the user, etc., so that doesn't seem like a good solution to me.

推荐答案

关于此事的两篇文章:

将Wicket页面呈现为HTML电子邮件的字符串

将面板渲染为字符串

目前唯一的其他方法是使用 WicketTester ,但我不记得有关如何做到这一点的细节。

Currently the only other approach was using WicketTester for that, but I do not remember details how to do that.

这篇关于Wicket:如何以编程方式呈现页面并将结果作为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆