The moose likes JSF and the fly likes How to add a button to the first row of a dataTable Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JSF
Reply Bookmark "How to add a button to the first row of a dataTable" Watch "How to add a button to the first row of a dataTable" New topic
Author

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

soumya kalla
Greenhorn

Joined: Jun 05, 2006
Posts: 12
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

Joined: Jan 10, 2002
Posts: 56529
    
  14

Please be sure to post JSF questions in the JSF forum. I have moved this one for you.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 14571
    
    7

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


Customer surveys are for companies who didn't pay proper attention to begin with.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
HtmlDataTable.getRowIndex() returns the row number of the table. So do:

JSF

MyBean


Code depot of a Java EE / JSF developer | JSF / Eclipse / Tomcat kickoff tutorial | DAO kickoff tutorial | I ♥ Unicode
soumya kalla
Greenhorn

Joined: Jun 05, 2006
Posts: 12
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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to add a button to the first row of a dataTable
 
Similar Threads
selectBooleanCheckbox
nested datatable not working
InputText in DataTable does not store value
strachable columns in jsf
Non-unique IDs generated by MyFaces Tomahawk t:columns tag