【问题标题】:Using getText() with more than one parameter in Struts 2 and JSP在 Struts 2 和 JSP 中使用带有多个参数的 getText()
【发布时间】:2014-01-29 18:05:14
【问题描述】:

我正在使用 JSP 开发 Struts2 框架。我的 *.properties 文件中有:

hover_remove=Remove access to {0} at {1}`

我在我的 JSP 中有一个提交标签:

title="%{getText('hover_remove', new String[]{{appLabel}, {locationLabel}})}"

这可以在 Java 中工作,但我在 JSP 中收到以下错误:

/WEB-INF/pages/admin/cm/view.jsp(9,287) 
JSPG0055E: Unable to create an xml attribute from name


在 JSP 中使用getText(String, List String[]) 有什么技巧吗?

【问题讨论】:

  • String?什么字符串? some_cool_package.String 还是 java.lang.String?提示:问题中有提示。 :)
  • @AleksandrM 谢谢!它现在显示了价值。但是,它显示的不是“第二次删除对第一个的访问”,而是显示“在[第二个]删除对[第一个]的访问”。是否可以删除方括号?当我只用一个测试时:"%{getText('hover_remove', {appLabel})}" 它显示正确。

标签: jsp struts2 properties-file dynamic-variables


【解决方案1】:

如果要创建 String-s 数组,则需要对类使用 FQN 并删除不需要的大括号。

title="%{getText('hover_remove', new java.lang.String[]{appLabel, locationLabel})}"

但是您可以使用getText 方法,该方法接受List 作为第二个参数,并利用OGNL 列表创建功能。在 OGNL 中要创建一个列表,您需要简单地将表达式列表放在花括号中。

title="%{getText('hover_remove', {appLabel, locationLabel})}"

【讨论】:

  • 这是额外的括号。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多