繁体   English   中英

使用循环在 JSF 中创建命令按钮?

[英]Create commandButton in JSF using loop?

对于数组中的示例,有

编辑 --> #{testBean.edit}
删除 --> #{testBean.delete}
复制 --> #{testBean.copy}

是否可以使用循环或其他东西创建命令按钮

for(i=0;i<=array.length;i++)<br>
{
print '<h:commandbutton value="#{testBean.array.name}" action="#{testBean.array.action}" />'
}

所以 output 应该像

<h:commandbutton value="Edit" action="#{testBean.edit}" />
<h:commandbutton value="Delete" action="#{testBean.delete}" />
<h:commandbutton value="Copy" action="#{testBean.copy}" />

只有将集合(地图?)更改为类似

Edit --> edit
Delete --> delete
Copy --> copy

例如

Map<String, String> buttons = new LinkedHashMap<String, String>();
buttons.put("Edit", "edit");
buttons.put("Delete", "delete");
buttons.put("Copy", "copy");

然后,您可以按如下方式循环它:

<ui:repeat value="#{bean.buttons}" var="button">
    <h:commandButton value="#{button.key}" action="#{bean[button.value]}" />
</ui:repeat>

作为替代方案,您可以在 bean 端以编程方式创建组件。

试过 Facelet 重复标签http://www.roseindia.net/jsf/repeat.shtml

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM