JSF 2.0中数据表中同一列中的不同组件 [英] Different components in same column in datatable in JSF 2.0

查看:64
本文介绍了JSF 2.0中数据表中同一列中的不同组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用JSF 2.0是否可以在数据表的单个列中使用不同类型的组件?

Is it possible to have different types of components in a single column in a data table using JSF 2.0?

我的要求是,根据label列的值,value列将具有相应的输入文本或选择列表.

My requirement is that based on the label column value, the value column will have an input text or select list accordingly.

当前,我正在尝试通过备用bean来执行此操作.我在arraylist中有labelvaluetype of component(例如"selectlist").

Currently I'm trying to do this via a backing bean. I have the label, value and type of component (e.g. "selectlist") in an arraylist.

当我在数据表中迭代此列表时,如何检查类型并根据结果创建输入列表或选择列表?

When I'm iterating this list in a data table, how do I check the type and depending on the outcome create either an input or select list?

推荐答案

在测试中使用rendered属性,该测试使用您使用的属性来区分输入列表和选择列表.

Use the rendered attribute with a test that uses whatever it is you use to distinguish between an input and a select list.

例如

<h:dataTable value="#{yourBacking.yourList} var="item">
    <h:column>
        <h:inputText value="#{item.value}" rendered="#{item.type == 'input'}" />
        <h:selectOneMenu value="#{item.value}" rendered="#{item.type == 'selectlist'}">
            <f:selectItems value="#{item.values}" />
        </h:selectOneMenu>
    </h:column>
</h:dataTable>

这篇关于JSF 2.0中数据表中同一列中的不同组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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