JSF:h:dataTable vs h:panelGrid

时间:2022-09-17 10:58:59

In JSF, h:dataTable and h:panelGrid both create html table-tags.

在JSF中,h:dataTable和h:panelGrid都创建html表格标记。

What is the difference between both?

两者的区别是什么?

When to use one or the other?

什么时候使用?

3 个解决方案

#1


16  

As it names indicates h:dataTable is used mostly for displaying a table containing data from some of the models in your application. Here is an usage example.

正如它的名称所示,h:dataTable主要用于显示包含应用程序中某些模型的数据的表。下面是一个使用示例。

<h:dataTable value="#{dataTableBean.items}" var="item">
    <h:column>
        <f:facet name="header" >
            <h:outputText value="Item Category"/>
        </f:facet>    
        <h:outputText value="#{item.category}"/>
    </h:column>
</h:dataTable>

The h:panelGrid is used mostly for layout and placing of elements purpose. Here is an usage example.

h:panelGrid主要用于布局和放置元素的目的。下面是一个使用示例。

<h:panelGrid id="panel" columns="2" border="1">
    <h:outputText value="First Name:" />
    <h:inputText id="first" value="#{backingBean.user.firstName}" />
    <h:outputText value="Last Name:" />
    <h:inputText id="last" value="#{backingBean.user.lastName}" />
</h:panelGrid>

#2


5  

The dataTable is a model-driven data output component. For every row in your model, the component can set the state of its children for every phase of the JSF lifecycle. This behaviour is beneficial or detrimental depending on what you're trying to achieve.

dataTable是一个模型驱动的数据输出组件。对于模型中的每一行,组件可以为JSF生命周期的每个阶段设置其子元素的状态。这种行为是有益的或有害的,取决于你想要达到的目标。

By contrast, the panelGrid is just a layout control.

相比之下,panelGrid只是一个布局控件。

The difference is (very) roughly analogous to the difference between JTable and JPanel.

差异(非常)大致类似于JTable和JPanel之间的区别。

#3


3  

You should use a panelGrid when you know the number of rows and columns that you want to display, you have to define all the child components yourself (manually, the panelGrid will not add any rows/collumns by itself) and the panelGrid will arrange them. DataGrid on the other hand is used when you have a data structure (like a collection) with an indetermined size, then you just have to specify the columns you want to print and the dataGrid will iterate over that collection creating a row for each entry.

当您知道要显示的行和列的数量时,您应该使用一个panelGrid,您必须自己定义所有子组件(手动地,panelGrid本身不会添加任何行/collumns),而panelGrid将会安排它们。另一方面,DataGrid是在具有不确定大小的数据结构(比如集合)时使用的,然后您只需指定要打印的列,DataGrid将遍历该集合,为每个条目创建一行。

#1


16  

As it names indicates h:dataTable is used mostly for displaying a table containing data from some of the models in your application. Here is an usage example.

正如它的名称所示,h:dataTable主要用于显示包含应用程序中某些模型的数据的表。下面是一个使用示例。

<h:dataTable value="#{dataTableBean.items}" var="item">
    <h:column>
        <f:facet name="header" >
            <h:outputText value="Item Category"/>
        </f:facet>    
        <h:outputText value="#{item.category}"/>
    </h:column>
</h:dataTable>

The h:panelGrid is used mostly for layout and placing of elements purpose. Here is an usage example.

h:panelGrid主要用于布局和放置元素的目的。下面是一个使用示例。

<h:panelGrid id="panel" columns="2" border="1">
    <h:outputText value="First Name:" />
    <h:inputText id="first" value="#{backingBean.user.firstName}" />
    <h:outputText value="Last Name:" />
    <h:inputText id="last" value="#{backingBean.user.lastName}" />
</h:panelGrid>

#2


5  

The dataTable is a model-driven data output component. For every row in your model, the component can set the state of its children for every phase of the JSF lifecycle. This behaviour is beneficial or detrimental depending on what you're trying to achieve.

dataTable是一个模型驱动的数据输出组件。对于模型中的每一行,组件可以为JSF生命周期的每个阶段设置其子元素的状态。这种行为是有益的或有害的,取决于你想要达到的目标。

By contrast, the panelGrid is just a layout control.

相比之下,panelGrid只是一个布局控件。

The difference is (very) roughly analogous to the difference between JTable and JPanel.

差异(非常)大致类似于JTable和JPanel之间的区别。

#3


3  

You should use a panelGrid when you know the number of rows and columns that you want to display, you have to define all the child components yourself (manually, the panelGrid will not add any rows/collumns by itself) and the panelGrid will arrange them. DataGrid on the other hand is used when you have a data structure (like a collection) with an indetermined size, then you just have to specify the columns you want to print and the dataGrid will iterate over that collection creating a row for each entry.

当您知道要显示的行和列的数量时,您应该使用一个panelGrid,您必须自己定义所有子组件(手动地,panelGrid本身不会添加任何行/collumns),而panelGrid将会安排它们。另一方面,DataGrid是在具有不确定大小的数据结构(比如集合)时使用的,然后您只需指定要打印的列,DataGrid将遍历该集合,为每个条目创建一行。