- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在对一些 JSF 文件进行国际化,因此我正在外部化字符串(以及使用占位符连接字符串)。我对 JSF 的经验很少(今天和昨天),所以如果我的问题有明显的答案,请原谅!
我一直在为简单的占位符成功使用 h:outputFormat 标签(和 f:param 标签),但现在我想用 commandLink 组件替换占位符。
即
<h:outputFormat value="#{adminMsgs.scheduleUpdateLink} ">
<h:commandLink value="#{adminMsgs.update}" action="refresh" />
</h:outputFormat>
属性文件:
scheduleUpdateLink = After waiting a few seconds, please {0} the page.
update = update
并按照这些行输出:
After waiting a few seconds, please <a href="#" class="..." onclick="...;return false;">update</a> the page.
这不起作用(更新链接出现在“scheduleUpdateLink”文本之前),有人知道我该怎么做吗?
提前致谢。
编辑/更新
感谢您的回复 McDowell - 非常有用,但仍然没有完全解决我的问题。我还需要对输入框 (h:inputText) 执行相同的操作,并且可能还会出现一个资源字符串中有多个占位符的情况。因此,我不能保证顺序,比如说,阿拉伯语,将是相同的。
如果我使用 Java 函数;你知道是否有一种方法可以将 JSF 标签作为字符串传递,例如<h:outputFormat value=..
.并使用 faces 上下文获取呈现的 HTML,然后我可以将其插入相应的占位符并作为纯 HTML 返回?或者沿着这些思路的任何其他想法?
干杯。
最佳答案
h:outputFormat标签将(据我所知)只使用 f:param child 作为参数。
如果消息是链接(而不是 h:commandLink ),您可以使用 HTML 文字:
<h:outputFormat escape="false"
value="...seconds, please <a href='etc..." />.
我不建议尝试通过这样做来模拟 h:commandLink。可能会在 third party library 中找到更丰富的 h:commandLink 版本这正是您想要的。
将字符串一分为二是可行的,但这会给翻译带来困难,而且翻译质量可能会受到影响(尤其是如果您经常这样做的话)。
我会考虑使用这样的自定义函数:
<f:loadBundle basename="i18n.I18n" var="bundle" />
<h:outputText value="#{i18n:fragment(bundle.scheduleUpdateLink, 0)}" />
<h:commandLink>
<h:outputText value="#{bundle.update}" />
</h:commandLink>
<h:outputText value="#{i18n:fragment(bundle.scheduleUpdateLink, 1)}" />
呈现的输出是以下形式:
After waiting a few seconds, please <script type="text/javascript"><!--
/*JavaScript elided*/
//-->
</script><a href="#"
onclick="return oamSubmitForm('someClientId');">update</a> the page.
该函数由一个静态方法支持,该方法拆分字符串并返回请求的片段:
public static String fragment(String string, int index) {
// TODO: regex probably not complete; ask stackoverflow!
// see http://java.sun.com/javase/6/docs/api/java/text/MessageFormat.html
final String regex = "\\{\\d.*?\\}";
String[] fragments = string.split(regex, index + 2);
return fragments[index];
// TODO: error handling
}
根据您的 View 技术(Facelets 或 JSP),函数声明略有不同:
编辑:基于更多信息
JSF 采用声明式方法来构建接口(interface)。您想要一个动态 UI,其中的子项根据它们在翻译后的字符串中出现的顺序排序。这两件事是矛盾的,但并非全无。
有几种方法可以解决这个问题。
.
<ed:formatPane string="click {0} after filling in forename {1} and surname {2}">
<h:commandLink value="#{bundle.linkMsg}" />
<h:inputText value="#{bean.prop1}" />
<h:inputText value="#{bean.prop2}" />
</ed:formatPane>
仅替换 h:outputFormat 的渲染器以支持任意子项而不是创建完整的自定义控件可能(并且工作更少),但我反对它,因为它可能会导致长期困惑维护。
可能有人已经按照我的建议编写了一个自定义控件(这很难算作原创)。
关于java - JSF : commandLink as a parameter for outputFormat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1205386/
目前我正在尝试创建一个 Web 部署包。所以我在我的项目的根目录中添加了一个 parameters.xml 并指定了一些自定义参数。 我发现我的很多参数都部分相同。所以我想做某种参数引用。寻找这个,我
如何设置我的 Symfony 2 项目以使用 parameters.yml 而不是 parameters.ini? 在 Controller 中,我可以像这样从 parameters.ini 中获取变
有什么建议说明为什么此 AWS CloudFormation 不断回滚吗? { "Description" : "Single Instance", "Resources" : {
PARAMETERS: p_1 TYPE i, p_2 TYPE i. 因此在初始屏幕中,我看到了 2 个文本框,每个参数一个。 如果我填写其中一个,但不按回车键,然后我在第二个上调用 F4 帮助,我
我需要存储 Parameter由 Build() 返回作为 Parameter (因为我将参数存储在一个数组中,另一种方法就是为每个参数数量复制粘贴相同的类太多,因为 c# 没有可变参数泛型)。 问题
我正在为我的 CS 类(class)做作业,它使用了 const,我对何时使用它们感到有点困惑。 这3个函数有什么区别? int const function(parameters) int fu
在 xgboost 的文档中,我读到: base_score [default=0.5] : the initial prediction score of all instances, global
我正在创建一个新的 REST 服务。 向 REST 服务传递参数的标准是什么。在 Java 的不同 REST 实现中,您可以将参数配置为路径的一部分或请求参数。例如, 路径参数 http://www.
在我的程序中,我需要验证传递给程序的参数是一个整数,所以我创建了这个小函数来处理用户键入“1st”而不是“1”的情况。 问题是它根本不起作用。我尝试调试,我只能告诉你参数是 12,long 是 2。(
谁能告诉我如何使用存储在 &rest 指定值中的参数。 我已经阅读了很多,似乎作者只知道如何列出所有参数。 (defun test (a &rest b) b) 这很高兴看到,但并不是很有用。 到目前
我使用 git 有一段时间了,但大多数时候我更喜欢与 Intelij IDEA 的集成。现在,为了扩展我对系统的知识和理解,我决定更多地使用命令行。我观察到的是有两种类型的参数: --paramete
我正在用 RAML 编写一些 REST 文档,但我被卡住了。 我的问题: - 我有一个用于搜索的 GET 请求,它可以采用参数“id”或( 独占或 )“引用”。拥有 只有其中之一 是必须的。 我知道怎
我定义了一个这样的 Action : /secure/listaAnnunci.action /login.jsp 我可以从 Action 内部访问参数吗?谢谢 最佳答案 您需要实现 S
我有一个 TeamCity 8.0.3 项目,其中包含多个配置,其中有一个通用参数(定义为项目参数):targetServerIP .这些配置之一是“一键部署”,它通过使用快照依赖项启动其他配置。我已
try{ Class.forName("com.mysql.jdbc.Driver"); mycon = DriverManager.getConnec
我在实际的 javascript 项目中遇到了一个非常奇怪的情况。我创建了一个自定义事件并将数组放入该事件 $.publish("merilon/TablesLoaded", getTables())
在使用参数数组进行插入/更新期间,可以忽略一个/一些特定行的一个/一些参数。 我提供了一个简单的例子。想象一下,我们有一个包含 3 列的表:X、Y 和 Z。我们想在 block 中执行更新(如果缺少某
如何编写接受未定义参数的函数?我想它可以像那样工作: void foo(void undefined_param) { if(typeof(undefined_param) == int) {
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界. 这篇CFSDN的博客文章PDO版本问题 Invalid parameter number: no
Jenkins 管道作业如下所示: 部分 Jenkinsfile(我们使用脚本化管道)是: properties([parameters([string(defaultValue: "", descr
我是一名优秀的程序员,十分优秀!