tags:

views:

789

answers:

4

HI All,

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:

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

Since the dataTable tag only has a sub tag h:column and NO h:row I am having issues with this. 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. 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 thoguhts will be much appreciated.

A: 

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...

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.

romaintaz
+3  A: 

Is it just for a non-repeating data? If so, use <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>). 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. The <c:for> gets processed before the <h:panelGrid>. Should work.

Damo
A: 

HI,

Thanks for the replies. My current code is like below. First column just writes out all the labels which are the tables headers and the second column writes out all the values. The values get printed weirdly if some values are blank and messes up the formatting.

<h:panelGroup rendered="#{imeiValidationHandler.showImeiDetails}"> <br/>
    <h5><h:outputText style="color:#FF0000;" value="#{myBundle.imei_is_present}" /></h5>
    <h:dataTable var="imeiInfo" value="#{imeiValidationHandler.imeiInfoBeanList}" binding="#{imeiValidationHandler.dataTable}"
                 styleClass="dataTable">
     <h:column>
                        <h6><h:outputText value="#{myBundle.device_description_label}"/></h6><br/>
                        <h6><h:outputText value="#{myBundle.device_model_label}"/></h6><br/>
                        <h6><h:outputText value="#{myBundle.customer_email_label}"/></h6><br/>
                        <h6><h:outputText value="#{myBundle.mygarmin_username_label}"/></h6><br/>
                        <h6><h:outputText value="#{myBundle.is_registered_label}"/></h6><br/>
                        <h6><h:outputText value="#{myBundle.registered_mdn_label}"/></h6><br/>
                        <h6><h:outputText value="#{myBundle.verified_mdn_label}"/></h6><br/>
     </h:column>

     <h:column>
      <h6><h:outputText value="#{imeiInfo.deviceDescription}"></h:outputText></h6><br/>
      <h6><h:outputText value="#{imeiInfo.deviceModel}"></h:outputText></h6><br/>
      <h6><h:outputText value="#{imeiInfo.userEmail}"></h:outputText></h6><br/>
      <h6><h:outputText value="#{imeiInfo.ldapUserName}"></h:outputText></h6><br/>
      <h6><h:outputText value="#{imeiInfo.active}"></h:outputText></h6><br/>
      <h6><h:outputText value="#{imeiInfo.mdn}"></h:outputText></h6><br/>
      <h6><h:outputText value="#{imeiInfo.registeredMdn}"></h:outputText></h6><br/>
     </h:column>
    </h:dataTable>   
   </h:panelGroup>
msharma
A: 

HI,

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

Any ideas? Thanks.

msharma