【问题标题】:How to display the label and value attributes as the label in a jsp如何将标签和值属性显示为jsp中的标签
【发布时间】:2013-01-22 23:41:09
【问题描述】:

我正在使用下面的代码来显示一个分支列表。

<html:option value="">--Select Branch--</html:option>
<html:optionsCollection name="branchList" label="label" value="key"/>

如何在标签中同时显示分支标签和分支值。例如:现在它显示标签为“西雅图”,值为“SEA”。我希望值保持不变,但标签显示为“西雅图(SEA)”

另外,这是一个jsp的一部分。 更新:应用程序使用 struts 框架。

【问题讨论】:

  • 这不是标准的 JSP。您正在使用一些专有的 MVC 框架,它提供用于 JSP 的标记库,例如 Struts。请相应地编辑问题以包含有关所使用框架的信息。
  • 是的,先生。它使用支柱。 “分支列表”是从动作类传递的。

标签: html jsp struts label key-value


【解决方案1】:

将以下方法添加到您的 bean:

public String getDisplayedLabel() {
    return label + "(" + key + ")";
}

并使用

<html:optionsCollection name="branchList" label="displayedLabel" value="key"/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多