aspose file tools*
The moose likes JSF and the fly likes Limiting rowsize in h:dataTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Limiting rowsize in h:dataTable" Watch "Limiting rowsize in h:dataTable" New topic
Author

Limiting rowsize in h:dataTable

Gangadhara Rao
Greenhorn

Joined: Jun 02, 2007
Posts: 7
Hello All,

I am using <h:dataTable> to display labels , for providing pagenation(I can not use any of the existing one as I have new requirment).

My Problem is , the label display should come in one row.

Is there any way out for fixing the number of rows in <h:datTable>.

As of now I am getting the labels in seperate rows by the following code

<h:dataTable border="0" cellpadding="2" cellspacing="0"
columnClasses="columnClass1" headerClass="headerClass"
footerClass="footerClass" rowClasses="rowClass1"
styleClass="dataTable" id="table2" value="#{pc_DataTableDemoCTIView.labelDetails}" var="varlabelDetails">
<h:column>
<h:commandLink styleClass="commandLink" id="link2" action="#{pc_DataTableDemoCTIView.doLink1Action}">
<hutputText id="text7" value="#{varlabelDetails.pageLabel}" styleClass="outputText">
</hutputText>
<f:param name="LabelKey" value="#{varlabelDetails.pageLabel}"></f:param>
</h:commandLink>
</h:column>
</h:dataTable>

Thanks in advance.

Gangadhar
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16142
    
  21

The basic way you limit the rows in the datatable is by limiting the rows in the data model collection.

However, there's a paging control that is part of the MyFaces Tomahawk tag set and it can be combined with a datatable to not only limit the number of rows displayed, but also to manage the data display paging itself. You might want to check it out.
[ July 09, 2007: Message edited by: Tim Holloway ]

Customer surveys are for companies who didn't pay proper attention to begin with.
Gangadhara Rao
Greenhorn

Joined: Jun 02, 2007
Posts: 7
Thank you.

Could you provide me sample code.
mano ranjan
Ranch Hand

Joined: Jul 12, 2007
Posts: 102
Hi
You can use row attribute available in datatable and "first" attribute for your pagnation concept
Gangadhara Rao
Greenhorn

Joined: Jun 02, 2007
Posts: 7
The dataTable Collection object(ArrayList) has more than one HashMap object in it.

To be specific the sample back-end code would be like

ArrayList data=new ArrayList();
for(i=0;i<6;i++)
{
HashMap map=new HashMap();
map.put("PageLabel","Page"+i);
data.add(map);
}
retrun data;

A normal datatable would display it in 6 rows. Now my requirement needs to display these 6 rows in a single row.

Like I have explained you, the existing display of JSF styles does'nt suit my requirement.

Please suggest me as to how it can be achieved.

Thank you
mano ranjan
Ranch Hand

Joined: Jul 12, 2007
Posts: 102
Hi
No need to write a back end code for this issue .
Gangadhara Rao
Greenhorn

Joined: Jun 02, 2007
Posts: 7
Hi ManoRanjan,

I could'nt understand the code snippet which you gave. But I tried out the way , giving first and rows.

I gave first to be zero and rows to be one. It printed out only one row.

It should be some thing like Dynamic Columns having hyper links, depending on my back end collection object size.

When I used data table it is printing all the labels with hyperlinks now in single row. My requirement is to give a weblabel sort of pagenation but the label format should be a different one.

Depending on the number of records I get , I will have to display to labels. My logic is working fine except this single row Issue.

For clarity I am pasting the code....

JSP......


<h:dataTable border="0" cellpadding="2" cellspacing="0"
columnClasses="columnClass1" headerClass="headerClass"
footerClass="footerClass" rowClasses="rowClass1"
styleClass="dataTable" id="table2" value="#{pc_DataTableDemoCTIView.labelDetails}" var="varlabelDetails">
<h:column>
<h:commandLink styleClass="commandLink" id="link2" action="#{pc_DataTableDemoCTIView.doLink1Action}">
<hutputText id="text7" value="#{varlabelDetails.pageLabel}" styleClass="outputText">
</hutputText>
<f:param name="LabelKey" value="#{varlabelDetails.pageLabel}"></f:param>
</h:commandLink>
</h:column>
</h:dataTable>


Managed Bean.....

public ArrayList getLabelDetails() {
System.out.println("Beginning of the method getLabelDetails() in ManagedBean");
ArrayList innerList=null;
try
{
if(request.getAttribute(PortletConstants.LABELS_TO_DISPLAY)!=null)
labelDetails=(ArrayList)request.getAttribute(PortletConstants.LABELS_TO_DISPLAY);
System.out.println("Label Detials are::"+labelDetails);
}
catch(NullPointerException npe)
{
System.out.println(npe.getMessage());
}
System.out.println("Exiting the method getLabelDetails() in ManagedBean");
return labelDetails;
}

I am forming these labels in a dynamic way in diffferent method and setting it in Request.

As of now the label display is like the following way...

1-20 >>
| 21-40 >>
| 41-60 >>
| 61-80 >>
| 81-90 >>

The Actual display should be like

1-20 >> | 21-40 >> | 41-60 >> | 61-80 >> | 81-90 >>
------- -------- --------- -------- --------

Thank you,
Gangadhar
Gabriel Claramunt
Ranch Hand

Joined: May 26, 2007
Posts: 375

Look at Apache's MyFaces Tomahawk dataList component
Probably you can get the functionality you're looking for.


Gabriel
Software Surgeon
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Limiting rowsize in h:dataTable