简体   繁体   English

使用JSF dataTable显示数据

[英]Displaying data using JSF dataTable

I want to display data using the h:dataTable tags in JSF The data I am displaying has to be in a format like this: 我想在JSF中使用h:dataTable标签显示数据我显示的数据必须是这样的格式:

Name:   XXXX
ID:  8989
Age:    32

I have seen several examples on the web that tell you how to display the data like this: 我在网上看到了几个例子,告诉你如何显示这样的数据:

Name ID Age XXX 8989 32 姓名ID年龄XXX 8989 32

Since the dataTable tag only has a sub tag h:column and NO h:row I am having issues with this. 由于dataTable标签只有一个子标签h:column和NO h:row我遇到了问题。 Is there a better way to do this? 有一个更好的方法吗? I have implemented the first format I mentioned using h:datable and h:column , so first I just write out all the column headers in column 1 and then I write out all the values in column2. 我已经使用h:datableh:column实现了我提到的第一种格式,所以首先我只写出第1列中的所有列标题,然后写出column2中的所有值。 The issue I am facing is that when one of the values is blank the next value gets printed in its place and the data appears wrong, this is really a formatting issue. 我面临的问题是,当其中一个值为空时,下一个值将打印在其位置并且数据显示错误,这实际上是格式化问题。 When data is blank it should leave space for it and then print the next value in the next row. 当数据为空时,它应为其留出空间,然后在下一行中打印下一个值。 Hope I am making sense, any thoughts will be much appreciated. 希望我有意义,任何想法都会受到高度赞赏。


I tried adding the below : 我尝试添加以下内容:

<h6><h:outputText value="#{empty imeiInfo.userEmail ? '&#160;' : imeiInfo.userEmail}"></h:outputText></h6><br/>

But there is a syntax error in this which I cannot figure out, the message I get is: 但是这里有一个语法错误,我无法弄清楚,我得到的信息是:

Syntax error in EL EL中的语法错误

Any ideas? 有任何想法吗? Thanks. 谢谢。

Is it just for a non-repeating data? 它只是针对非重复数据吗? If so, use <h:panelGrid> 如果是这样,请使用<h:panelGrid>

For example: 例如:

<h:panelGrid columns="2">
   <h:outputText value="Name:"/>
   <h:outputText value="#{person.name}"/>
   <h:outputText value="ID:"/>
   <h:outputText value="#{person.id}"/>
   <h:outputText value="Age:"/>
   <h:outputText value="#{person.age}"/>
</h:panelGrid>

If it is for repeating data (ie. multiple 'persons') then you have a number of options depending on what other libraries you are using. 如果是重复数据(即多个'人'),那么根据您使用的其他库,您有许多选项。 For example: 例如:

1: Build your own table using Facelets <ui:repeat> (you could do the same with <c:for> ). 1:使用Facelets <ui:repeat>构建自己的表(您可以对<c:for>执行相同操作)。 For example: 例如:

<table>
    <ui:repeat value="#{myBean.persons}" var="person">
        <tr>
           <td>
              <h:outputText value="Name:"/>
           </td>
           <td>
              <h:outputText value="#{person.name}"/>
           </td>
        </tr>
        <tr>
           <td>
              <h:outputText value="ID:"/>
           </td>
           <td>
              <h:outputText value="#{person.id}"/>
           </td>
        </tr>
        <tr>
           <td>
              <h:outputText value="Age:"/>
           </td>
           <td>
              <h:outputText value="#{person.age}"/>
           </td>
        </tr>
        <tr>
           <td colspan="2">
              &#160;
           </td>
        </tr>
    </ui:repeat>
</table>

EDIT: I haven't tried this but you should be able to surround the in the first example ( <h:panelGrid> ) with a <c:for> to render repeating elements. 编辑:我没有尝试这个,但你应该能够在第一个例子( <h:panelGrid> )中用<c:for>来包围重复元素。 The <c:for> gets processed before the <h:panelGrid> . <c:for><h:panelGrid>之前处理。 Should work. 应该管用。

I'm not sure to understand how you want to render your table. 我不确定你想要如何呈现你的桌子。 I think it would help us if you could provide the JSF code of your table... 如果您能提供表格的JSF代码,我认为这对我们有帮助...

However, concerning this point: 但是,关于这一点:

When data is blank it should leave space for it and then print the next value in the next row 当数据为空时,它应为其留出空间,然后在下一行中打印下一个值

maybe you can try something like that: 也许你可以试试这样的东西:

<h:outputText value="#{empty aRecord.name ? '&#160;' : aRecord.name}"/>

This code will render an unbreakable space if the name of the record is empty, otherwise it will render the name of the record. 如果记录的名称为空,此代码将呈现不可破坏的空间,否则将呈现记录的name

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

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