Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add a button to the first row of a dataTable

 
soumya kalla
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am using myFaces for my dataTable. The first cloumn in my table has checkboxes and the other columns have data.
In the first row I want to add a button instead of a checkbox.


<t:dataTable id="fooPB" value="#{phoneBooksTableDataBeanDto.tableRows}"
var="tableRow" rows="5" styleClass="dataTable"
headerClass="tableHeader" first="0"
columnClasses="checkbox, string, string, string, string"
rowClasses="odd, even">

<t:column>
<f:facet name="header">
</f:facet>
<h:selectBooleanCheckbox value="#{tableRow.selected}" />
</t:column>
<t:column>
<f:facet name="header">
<tutputText value="#{screen.lastName}" />
</f:facet>
<t:inputText value="#{tableRow.lastName}" />
</t:column>
<t:column>
<f:facet name="header">
<tutputText value="#{screen.firstName}" />
</f:facet>
<t:inputText value="#{tableRow.firstName}" />
</t:column>
<t:column>
<f:facet name="header">
<tutputText value="#{screen.phoneNumber}" />
</f:facet>
<t:inputText value="#{tableRow.phoneNumber}" />
</t:column>
<t:column>
<f:facet name="header">
<tutputText value="#{screen.notes}" />
</f:facet>
<t:inputText value="#{tableRow.notes}" />
</t:column>
</t:dataTable>
</h:panelGrid>


i tried adding another set of <f:facet></f:facet> in each column below the header, but the row itself did not show up. Could somebody please tell me how I can add a button to the first row.

I hope my question is clear enough.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to post JSF questions in the JSF forum. I have moved this one for you.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Easiest way is to put BOTH in the first column and activate the one you want.

IIRC, using mythical controls because I've forgotten the exact myFaces ones and it's the idea that counts:

<z:buttonControl visible="${firstRow}" etc. />
<z:checkBoxControl visible="${! firstRow}" etc. />
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HtmlDataTable.getRowIndex() returns the row number of the table. So do:

JSF

MyBean
 
soumya kalla
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bauke,

Thankyou so much for the code. I tried it using the rowIndex just like you suggested and it worked.
I also thank the others for their help.

Soumya
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic